Timeout unit for TCP Keep Alive settings differs across frameworks
perclausen opened this issue · comments
Per Clausen commented
On non .NET Standard e.g. .NET Framework Socket.IOControl
is used to set keep alive settings where timeout unit is milli-seconds.
On .NET Standard Socket.SetSocketOption
is used to set keep alive settings where timeout unit is seconds.
https://github.com/Azure/amqpnetlite/blob/master/src/Net/SocketExtensions.cs
Workaround:
#if NETSTANDARD2_0
_connectionFactory.TCP.KeepAlive = new TcpKeepAliveSettings
{
KeepAliveTime = Convert.ToUInt32(TimeSpan.FromMinutes(1).TotalSeconds),
KeepAliveInterval = Convert.ToUInt32(TimeSpan.FromMinutes(0.5).TotalSeconds)
};
#else
_connectionFactory.TCP.KeepAlive = new TcpKeepAliveSettings
{
KeepAliveTime = Convert.ToUInt32(TimeSpan.FromMinutes(1).TotalMilliseconds),
KeepAliveInterval = Convert.ToUInt32(TimeSpan.FromMinutes(0.5).TotalMilliseconds)
};
#endif
Suggested fix options:
- Make
TcpKeepAliveSettings
propertiesKeepAliveTime
andKeepAliveInterval
of typeTimeSpan
and take care of the difference (Socket.IOControl
vsSocket.SetSocketOption
) inSocketExtensions.cs
(breaking change but consumers of the NuGet would know). - Update documentation for
KeepAliveTime
andKeepAliveInterval
to state that timeout is in seconds and take care of the difference (Socket.IOControl
vsSocket.SetSocketOption
) inSocketExtensions.cs
.