diff --git a/projects/RabbitMQ.Client/Impl/SocketFrameHandler.cs b/projects/RabbitMQ.Client/Impl/SocketFrameHandler.cs index b39b95370..4a970f00d 100644 --- a/projects/RabbitMQ.Client/Impl/SocketFrameHandler.cs +++ b/projects/RabbitMQ.Client/Impl/SocketFrameHandler.cs @@ -111,8 +111,11 @@ public TimeSpan ReadTimeout { try { - _socket.ReceiveTimeout = value; - _stream.ReadTimeout = (int)value.TotalMilliseconds; + if (value != default) + { + _socket.ReceiveTimeout = value; + _stream.ReadTimeout = (int)value.TotalMilliseconds; + } } catch (SocketException) { @@ -125,8 +128,11 @@ public TimeSpan WriteTimeout { set { - _socket.Client.SendTimeout = (int)value.TotalMilliseconds; - _stream.WriteTimeout = (int)value.TotalMilliseconds; + if (value != default) + { + _socket.Client.SendTimeout = (int)value.TotalMilliseconds; + _stream.WriteTimeout = (int)value.TotalMilliseconds; + } } } diff --git a/projects/Test/Integration/GH/TestGitHubIssues.cs b/projects/Test/Integration/GH/TestGitHubIssues.cs index 13f2be7fb..7f8810fb6 100644 --- a/projects/Test/Integration/GH/TestGitHubIssues.cs +++ b/projects/Test/Integration/GH/TestGitHubIssues.cs @@ -117,5 +117,19 @@ public async Task TestBasicConsumeCancellation_GH1750() Assert.False(sawConnectionShutdown); } + + [Fact] + public async Task TestHeartbeatTimeoutValue_GH1756() + { + var connectionFactory = new ConnectionFactory + { + AutomaticRecoveryEnabled = true, + RequestedHeartbeat = TimeSpan.Zero, + }; + + _conn = await connectionFactory.CreateConnectionAsync("some-name"); + + Assert.True(_conn.Heartbeat != default); + } } }