From a7bba2d2684f6fad2fee3abbb4e7108089c5ab62 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Oct 2025 19:04:14 -0500 Subject: disable (effectively) the write buffer for connections other than distributed --- src/slskd/Application.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 48b8fb22..7ebc5d10 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -374,7 +374,7 @@ namespace slskd var connectionOptions = new ConnectionOptions( readBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Read, writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Write, - writeQueueSize: OptionsAtStartup.Soulseek.Connection.Buffer.WriteQueue, + writeQueueSize: int.MaxValue, // no write queue for peer, server or transfer connections connectTimeout: OptionsAtStartup.Soulseek.Connection.Timeout.Connect, inactivityTimeout: OptionsAtStartup.Soulseek.Connection.Timeout.Inactivity, proxyOptions: proxyOptions); -- cgit v1.2.3 From 4d10f21b831ecb4135b6f56c1c37c9cf90931f99 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Oct 2025 19:04:52 -0500 Subject: set socket read and write timeouts --- src/slskd/Application.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 7ebc5d10..7754c4ef 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -380,8 +380,10 @@ namespace slskd proxyOptions: proxyOptions); // os-specific keepalive is configured for long-lived connections for the server and distributed parent/children - var serverOptions = connectionOptions.With(configureSocketAction: socket => ConfigureSocketKeepAlive(socket, OptionsAtStartup.Soulseek.Connection)); - var distributedOptions = connectionOptions.With(configureSocketAction: socket => ConfigureSocketKeepAlive(socket, OptionsAtStartup.Soulseek.Connection)); + var serverOptions = connectionOptions.With(configureSocketAction: socket => ConfigureSocketOptions(socket, OptionsAtStartup.Soulseek.Connection)); + var distributedOptions = connectionOptions.With( + writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.WriteQueue, // write queue set to keep distributed children from impacting performance + configureSocketAction: socket => ConfigureSocketOptions(socket, OptionsAtStartup.Soulseek.Connection)); var transferOptions = connectionOptions.With( readBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer, @@ -495,7 +497,7 @@ namespace slskd return Task.CompletedTask; } - private void ConfigureSocketKeepAlive(Socket socket, Options.SoulseekOptions.ConnectionOptions options) + private void ConfigureSocketOptions(Socket socket, Options.SoulseekOptions.ConnectionOptions options) { /* os-specific keepalive is configured for long-lived connections for the server and distributed parent/children @@ -507,6 +509,11 @@ namespace slskd */ try { + // these are set in Soulseek.NET too, but to be super, super sure, do it again; these options can cause + // I/O loops to hang indefinitely and are suspected to be a cause of 'stuck' transfers + socket.SendTimeout = options.Timeout.Inactivity; + socket.ReceiveTimeout = options.Timeout.Inactivity; + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); if (OperatingSystem.IsWindows() && OptionsAtStartup.Flags.LegacyWindowsTcpKeepalive) @@ -1391,8 +1398,8 @@ namespace slskd inactivityTimeout: connection.Timeout.Inactivity, proxyOptions: proxyPatch); - serverPatch = connectionPatch.With(configureSocketAction: socket => ConfigureSocketKeepAlive(socket, options: connection)); - distributedPatch = connectionPatch.With(configureSocketAction: socket => ConfigureSocketKeepAlive(socket, options: connection)); + serverPatch = connectionPatch.With(configureSocketAction: socket => ConfigureSocketOptions(socket, options: connection)); + distributedPatch = connectionPatch.With(configureSocketAction: socket => ConfigureSocketOptions(socket, options: connection)); transferPatch = connectionPatch.With( readBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer, -- cgit v1.2.3