From 18aa0569569984547162d4fb466d3f6328127c74 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 6 Sep 2025 18:57:30 -0500 Subject: fix bug causing an error to appear while editing a commented-out config --- src/slskd/Core/API/Controllers/OptionsController.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index e39c5fe1..25e9095a 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -190,6 +190,11 @@ namespace slskd.Core.API { var options = yaml.FromYaml(); + if (options is null) + { + return true; + } + if (!options.TryValidate(out var result)) { error = result.GetResultView(); -- cgit v1.2.3 From f7156c08b159875cc3f8b4e59cb3babd8e475cca Mon Sep 17 00:00:00 2001 From: encode42 Date: Sun, 21 Sep 2025 04:28:34 -0400 Subject: Support the ability for the web interface to listen on a unix socket --- config/slskd.example.yml | 1 + docs/config.md | 2 ++ src/slskd/Core/Options.cs | 9 +++++++++ src/slskd/Program.cs | 6 ++++++ 4 files changed, 18 insertions(+) (limited to 'src/slskd/Core') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 86e272ef..122ce4cf 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -143,6 +143,7 @@ # certificate: # pfx: ~ # password: ~ +# socket: ~ # url_base: / # content_path: wwwroot # logging: false diff --git a/docs/config.md b/docs/config.md index 053deea3..6bbd01cf 100644 --- a/docs/config.md +++ b/docs/config.md @@ -802,6 +802,7 @@ Logging of HTTP requests is disabled by default. | Command-Line | Environment Variable | Description | | ----------------- | -------------------------- | ------------------------------------------------- | | `-l\|--http-port` | `SLSKD_HTTP_PORT` | The HTTP listen port | +| `--http-socket` | `SLSKD_HTTP_SOCKET` | The unix listen socket | | `--url-base` | `SLSKD_URL_BASE` | The base url for web requests | | `--content-path` | `SLSKD_CONTENT_PATH` | The path to static web content | | `--http-logging` | `SLSKD_HTTP_LOGGING` | Determines whether HTTP requests are to be logged | @@ -810,6 +811,7 @@ Logging of HTTP requests is disabled by default. ```yaml web: port: 5030 + socket: ~ url_base: / content_path: wwwroot logging: false diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 4d4c1e68..af8f3c2f 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1812,6 +1812,15 @@ namespace slskd [Validate] [RequiresRestart] public HttpsOptions Https { get; init; } = new HttpsOptions(); + + /// + /// Gets the unix listen socket. + /// + [Argument(default, "http-socket")] + [EnvironmentVariable("HTTP_SOCKET")] + [Description("unix listen socket for web UI")] + [RequiresRestart] + public string Socket { get; init; } /// /// Gets the base url for web requests. diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 35ed87fc..8825485e 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -493,6 +493,12 @@ namespace slskd } }); } + + if (OptionsAtStartup.Web.Socket != null) + { + Log.Information($"Listening on socket {OptionsAtStartup.Web.Socket}"); + options.ListenUnixSocket(OptionsAtStartup.Web.Socket); + } }); builder.Services -- cgit v1.2.3 From 16fdab0d63bae249f32f12112e0745dcd4bdf2eb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 28 Sep 2025 14:43:42 -0500 Subject: tweak docs, assign validators for socket --- config/slskd.example.yml | 2 +- docs/config.md | 4 +++- src/slskd/Core/Options.cs | 20 +++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src/slskd/Core') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 122ce4cf..ad3c6113 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -136,6 +136,7 @@ # - ^.{1,2}$ # web: # port: 5030 +# socket: ~ # https: # disabled: false # port: 5031 @@ -143,7 +144,6 @@ # certificate: # pfx: ~ # password: ~ -# socket: ~ # url_base: / # content_path: wwwroot # logging: false diff --git a/docs/config.md b/docs/config.md index 6bbd01cf..10f296f5 100644 --- a/docs/config.md +++ b/docs/config.md @@ -793,6 +793,8 @@ soulseek: The default HTTP listen port is 5030, but can be anything between 1 and 65535. +A [unix domain socket](https://en.wikipedia.org/wiki/Unix_domain_socket) can be used on both unix-like operating systems and Windows. The specified socket file path must be absolute, and must point to a file that does not exist (slskd will manage it automatically). + The URL base option allows the application to operate behind a reverse proxy. Setting a base of "slskd" would make the web UI accessible at `http://:/slskd`. The content path can be used to force the application to serve static web content from a location other than the default (`wwwroot`). The application is designed to decouple the Web UI from the rest of the application to be replaceable. @@ -802,7 +804,7 @@ Logging of HTTP requests is disabled by default. | Command-Line | Environment Variable | Description | | ----------------- | -------------------------- | ------------------------------------------------- | | `-l\|--http-port` | `SLSKD_HTTP_PORT` | The HTTP listen port | -| `--http-socket` | `SLSKD_HTTP_SOCKET` | The unix listen socket | +| `--http-socket` | `SLSKD_HTTP_SOCKET` | The HTTP listen unix domain socket (UDS) path | | `--url-base` | `SLSKD_URL_BASE` | The base url for web requests | | `--content-path` | `SLSKD_CONTENT_PATH` | The path to static web content | | `--http-logging` | `SLSKD_HTTP_LOGGING` | Determines whether HTTP requests are to be logged | diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index af8f3c2f..352d23e9 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1807,21 +1807,23 @@ namespace slskd public int Port { get; init; } = 5030; /// - /// Gets HTTPS options. - /// - [Validate] - [RequiresRestart] - public HttpsOptions Https { get; init; } = new HttpsOptions(); - - /// - /// Gets the unix listen socket. + /// Gets the HTTP listen unix domain socket (UDS) path. /// [Argument(default, "http-socket")] [EnvironmentVariable("HTTP_SOCKET")] - [Description("unix listen socket for web UI")] + [Description("HTTP listen unix domain socket (UDS) path for web UI")] + [FileDoesNotExist] + [AbsoluteFilePath] [RequiresRestart] public string Socket { get; init; } + /// + /// Gets HTTPS options. + /// + [Validate] + [RequiresRestart] + public HttpsOptions Https { get; init; } = new HttpsOptions(); + /// /// Gets the base url for web requests. /// -- cgit v1.2.3 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 --- config/slskd.example.yml | 1 + docs/config.md | 7 ++++++- src/slskd/Core/Options.cs | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/slskd/Core') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index ad3c6113..419c0c9f 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -207,6 +207,7 @@ # timeout: # connect: 10000 # inactivity: 15000 +# transfer: 30000 # buffer: # read: 16384 # write: 16384 diff --git a/docs/config.md b/docs/config.md index 10f296f5..5a4d3155 100644 --- a/docs/config.md +++ b/docs/config.md @@ -705,10 +705,14 @@ Higher connect timeout values will help ensure that operations (browse, download Inactivity timeouts help the application determine when a distributed parent connection has stopped sending data and when connections that have delivered search results (and are unlikely to be used further) from remaining open longer than needed. Reducing this timeout can help low spec systems if port exhaustion is a concern but may result in the application "hunting" for a distributed parent connection needlessly. +Transfer connections use their own timeout value; other Soulseek clients regulate transfer speed by controlling how often data is sent (e.g. send full speed for 5 seconds, send nothing for 25 seconds), +and as such transfers can easily time out due to inactivity if using a lower value. This setting must be at least 30 seconds. + | Command-Line | Environment Variable | Description | | --------------------------- | ------------------------------- | ------------------------------------------------ | | `--slsk-connection-timeout` | `SLSKD_SLSK_CONNECTION_TIMEOUT` | The connection timeout value, in milliseconds | | `--slsk-inactivity-timeout` | `SLSKD_SLSK_INACTIVITY_TIMEOUT` | The connection inactivity value, in milliseconds | +| `--slsk-transfer-timeout` | `SLSKD_SLSK_TRANSFER_TIMEOUT` | The transfer connection timeout value, in milliseconds | #### **YAML** ```yaml @@ -716,7 +720,8 @@ soulseek: connection: timeout: connect: 10000 - inactivity: 15000 + inactivity: 15000 + transfer: 30000 ``` ### Buffers 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