Skip to content

Commit 21fb198

Browse files
authored
Merge pull request #1773 from rabbitmq/rabbitmq-dotnet-client-1756
Allow setting heartbeat timeout to `TimeSpan.Zero`
2 parents 75822ae + 2cb90b5 commit 21fb198

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

projects/RabbitMQ.Client/Impl/SocketFrameHandler.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ public TimeSpan ReadTimeout
111111
{
112112
try
113113
{
114-
_socket.ReceiveTimeout = value;
115-
_stream.ReadTimeout = (int)value.TotalMilliseconds;
114+
if (value != default)
115+
{
116+
_socket.ReceiveTimeout = value;
117+
_stream.ReadTimeout = (int)value.TotalMilliseconds;
118+
}
116119
}
117120
catch (SocketException)
118121
{
@@ -125,8 +128,11 @@ public TimeSpan WriteTimeout
125128
{
126129
set
127130
{
128-
_socket.Client.SendTimeout = (int)value.TotalMilliseconds;
129-
_stream.WriteTimeout = (int)value.TotalMilliseconds;
131+
if (value != default)
132+
{
133+
_socket.Client.SendTimeout = (int)value.TotalMilliseconds;
134+
_stream.WriteTimeout = (int)value.TotalMilliseconds;
135+
}
130136
}
131137
}
132138

projects/Test/Integration/GH/TestGitHubIssues.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,19 @@ public async Task TestBasicConsumeCancellation_GH1750()
117117

118118
Assert.False(sawConnectionShutdown);
119119
}
120+
121+
[Fact]
122+
public async Task TestHeartbeatTimeoutValue_GH1756()
123+
{
124+
var connectionFactory = new ConnectionFactory
125+
{
126+
AutomaticRecoveryEnabled = true,
127+
RequestedHeartbeat = TimeSpan.Zero,
128+
};
129+
130+
_conn = await connectionFactory.CreateConnectionAsync("some-name");
131+
132+
Assert.True(_conn.Heartbeat != default);
133+
}
120134
}
121135
}

0 commit comments

Comments
 (0)