Skip to content

Commit

Permalink
Merge pull request #1773 from rabbitmq/rabbitmq-dotnet-client-1756
Browse files Browse the repository at this point in the history
Allow setting heartbeat timeout to `TimeSpan.Zero`
  • Loading branch information
lukebakken authored Jan 30, 2025
2 parents 75822ae + 2cb90b5 commit 21fb198
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions projects/RabbitMQ.Client/Impl/SocketFrameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions projects/Test/Integration/GH/TestGitHubIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 21fb198

Please sign in to comment.