From e1a39de7d5e8127a2a3b52ecc5d09bb4961c40e0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 11 Oct 2025 00:28:41 -0500 Subject: add transfer timeout setting --- src/slskd/Core/Options.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 352d23e9..38416ca2 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1675,6 +1675,15 @@ namespace slskd [Description("connection inactivity timeout, in milliseconds")] [Range(1000, int.MaxValue)] public int Inactivity { get; init; } = 15000; + + /// + /// Gets the transfer connection timeout, in milliseconds. + /// + [Argument(default, "slsk-transfer-timeout")] + [EnvironmentVariable("SLSK_TRANSFER_TIMEOUT")] + [Description("transfer connection timeout, in milliseconds")] + [Range(30_000, int.MaxValue)] + public int Transfer { get; init; } = 60000; } /// -- cgit v1.2.3 From ef1038be546899752d37482d8ac2c239813c7315 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 11 Oct 2025 00:29:11 -0500 Subject: rename configureSocketAction to match the Soulseek.NET type --- src/slskd/Core/Extensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Extensions.cs b/src/slskd/Core/Extensions.cs index 65942180..db75cc9c 100644 --- a/src/slskd/Core/Extensions.cs +++ b/src/slskd/Core/Extensions.cs @@ -51,7 +51,7 @@ namespace slskd /// The connection timeout, in milliseconds, for client and peer TCP connections. /// The inactivity timeout, in milliseconds, for peer TCP connections. /// Optional SOCKS 5 proxy configuration options. - /// + /// /// The delegate invoked during instantiation to configure the server Socket instance. /// /// The new instance. @@ -63,14 +63,14 @@ namespace slskd int? connectTimeout = null, int? inactivityTimeout = null, ProxyOptions proxyOptions = null, - Action configureSocketAction = null) => new ConnectionOptions( + Action configureSocket = null) => new ConnectionOptions( readBufferSize: readBufferSize ?? o.ReadBufferSize, writeBufferSize: writeBufferSize ?? o.WriteBufferSize, writeQueueSize: writeQueueSize ?? o.WriteQueueSize, connectTimeout: connectTimeout ?? o.ConnectTimeout, inactivityTimeout: inactivityTimeout ?? o.InactivityTimeout, proxyOptions: proxyOptions ?? o.ProxyOptions, - configureSocket: configureSocketAction ?? o.ConfigureSocket); + configureSocket: configureSocket ?? o.ConfigureSocket); /// /// Creates a new instance of from this instance of . -- cgit v1.2.3 From 0dbcf34423aaf73730700cb1d31e140a6f2cc38a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 2 Nov 2025 18:41:06 -0600 Subject: make check of index case insensitive --- src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs b/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs index 9b3f14a8..8ae13734 100644 --- a/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs +++ b/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs @@ -41,8 +41,8 @@ public class Z07062025_TransferIndexesMigration : IMigration var idxes = SchemaInspector.GetDatabaseIndexes(ConnectionString); var txfers = idxes["Transfers"]; - var directionExists = txfers.Any(c => c.Name == "IDX_Transfers_Direction"); - var stateExists = txfers.Any(c => c.Name == "IDX_Transfers_State"); + var directionExists = txfers.Any(c => c.Name.Equals("IDX_Transfers_Direction", StringComparison.OrdinalIgnoreCase)); + var stateExists = txfers.Any(c => c.Name.Equals("IDX_Transfers_State", StringComparison.OrdinalIgnoreCase)); if (directionExists && stateExists) { -- cgit v1.2.3 From efe4164f73e9c13fdaf099b41a9230b4d87960d9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Nov 2025 19:30:04 -0600 Subject: add SQLite flags --- src/slskd/Core/Options.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 38416ca2..a569841f 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -461,6 +461,22 @@ namespace slskd [EnvironmentVariable("OPTIMISTIC_RELAY_FILE_INFO")] [Description("use uploaded relay shares as source of truth for file existence and size")] public bool OptimisticRelayFileInfo { get; init; } = false; + + /// + /// Gets a value indicating whether SQLite cache sharing should be disabled (set to Private). + /// + [Argument(default, "no-sqlite-cache-sharing")] + [EnvironmentVariable("NO_SQLITE_CACHE_SHARING")] + [Description("disable SQLite cache sharing")] + public bool NoSqliteCacheSharing { get; init; } = false; + + /// + /// Gets a value indicating whether SQLite pooling should be disabled. + /// + [Argument(default, "no-sqlite-pooling")] + [EnvironmentVariable("NO_SQLITE_POOLING")] + [Description("disable SQLite pooling")] + public bool NoSqlitePooling { get; init; } = false; } /// -- cgit v1.2.3 From 70f16315cf407bdaa5487e9b818acd98704714cf Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 16 Nov 2025 18:34:28 -0600 Subject: use an interceptor to set synchronous pragma for each connection --- src/slskd/Core/Data/SqlitePragmaInterceptor.cs | 55 ++++++++++++++++++++++++++ src/slskd/Program.cs | 5 +-- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/slskd/Core/Data/SqlitePragmaInterceptor.cs (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Data/SqlitePragmaInterceptor.cs b/src/slskd/Core/Data/SqlitePragmaInterceptor.cs new file mode 100644 index 00000000..b32982b1 --- /dev/null +++ b/src/slskd/Core/Data/SqlitePragmaInterceptor.cs @@ -0,0 +1,55 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd +{ + using System.Data.Common; + using System.Threading; + using System.Threading.Tasks; + using Microsoft.Data.Sqlite; + using Microsoft.EntityFrameworkCore.Diagnostics; + + /// + /// Intercepts SQLite database connections to set PRAGMAs immediately after opening. + /// + public class SqliteConnectionOpenedInterceptor : DbConnectionInterceptor + { + public override void ConnectionOpened(DbConnection connection, ConnectionEndEventData eventData) + { + if (connection is SqliteConnection) + { + using var cmd = connection.CreateCommand(); + cmd.CommandText = "PRAGMA synchronous=1;"; + cmd.ExecuteNonQuery(); + } + + base.ConnectionOpened(connection, eventData); + } + + public override async Task ConnectionOpenedAsync(DbConnection connection, ConnectionEndEventData eventData, CancellationToken cancellationToken = default) + { + if (connection is SqliteConnection) + { + using var cmd = connection.CreateCommand(); + cmd.CommandText = "PRAGMA synchronous=1;"; + await cmd.ExecuteNonQueryAsync(cancellationToken); + } + + await base.ConnectionOpenedAsync(connection, eventData, cancellationToken); + } + } +} diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 639d3a88..ee9e2d0c 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -1209,6 +1209,7 @@ namespace slskd services.AddDbContextFactory(options => { options.UseSqlite(connectionString); + options.AddInterceptors(new SqliteConnectionOpenedInterceptor()); if (OptionsAtStartup.Debug && OptionsAtStartup.Flags.LogSQL) { @@ -1230,9 +1231,7 @@ namespace slskd /* set (and validate) our desired PRAGMAs - note: synchronous mode wants to default to 2, and setting it here may not actually do anything - an alternative would be to set it at the start of each new connection, but i'm unsure if that - would have the intended effect. revisit later. + synchronous mode is also set upon every connection via SqliteConnectionOpenedInterceptor. */ ctx.Database.OpenConnection(); var conn = ctx.Database.GetDbConnection(); -- cgit v1.2.3 From e763715bd89cbf8c10537fc72905d4358caf8215 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 16 Nov 2025 18:37:55 -0600 Subject: remove file validation for unix sockets --- src/slskd/Core/Options.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index a569841f..61e2878c 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1837,7 +1837,6 @@ namespace slskd [Argument(default, "http-socket")] [EnvironmentVariable("HTTP_SOCKET")] [Description("HTTP listen unix domain socket (UDS) path for web UI")] - [FileDoesNotExist] [AbsoluteFilePath] [RequiresRestart] public string Socket { get; init; } -- cgit v1.2.3 From 277fed8cdd5187769479eed60754b300b96761eb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Nov 2025 17:33:00 -0600 Subject: add flag to enable logging of unobserved exceptions --- config/slskd.example.yml | 1 + src/slskd/Core/Options.cs | 9 +++++++++ src/slskd/Program.cs | 15 +++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/slskd/Core') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 419c0c9f..a0ca4f3f 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -13,6 +13,7 @@ # force_migrations: false # no_version_check: false # log_sql: false +# log_unobserved_exceptions: false # experimental: false # volatile: false # case_sensitive_reg_ex: false diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 61e2878c..ec94afcb 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -417,6 +417,15 @@ namespace slskd [RequiresRestart] public bool LogSQL { get; init; } = false; + /// + /// Gets a value indicating whether to log unobserved Exceptions. + /// + [Argument(default, "log-unobserved-exceptions")] + [EnvironmentVariable("LOG_UNOBSERVED_EXCEPTIONS")] + [Description("log unobserved exceptions (caution: verbose)")] + [RequiresRestart] + public bool LogUnobservedExceptions { get; init; } = false; + /// /// Gets a value indicating whether the application should run in experimental mode. /// diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index ee9e2d0c..07d08fca 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -1143,12 +1143,15 @@ namespace slskd })) .CreateLogger(); - // // occurs when a faulted task's unobserved exception is about to trigger exception escalation policy, which, by default, would terminate the process. - // TaskScheduler.UnobservedTaskException += (sender, e) => - // { - // Serilog.Log.Logger.Error(e.Exception, "Unobserved exception: {Message}", e.Exception.Message); - // e.SetObserved(); - // }; + if (OptionsAtStartup.Flags.LogUnobservedExceptions) + { + // log Exceptions raised on fired-and-forgotten tasks, which adds very little value but might help debug someday + TaskScheduler.UnobservedTaskException += (sender, e) => + { + Serilog.Log.Logger.Error(e.Exception, "Unobserved exception: {Message}", e.Exception.Message); + e.SetObserved(); + }; + } AppDomain.CurrentDomain.UnhandledException += (sender, e) => { -- cgit v1.2.3