Azure / amqpnetlite

AMQP 1.0 .NET Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timeout unit for TCP Keep Alive settings differs across frameworks

perclausen opened this issue · comments

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 properties KeepAliveTime and KeepAliveInterval of type TimeSpan and take care of the difference (Socket.IOControl vs Socket.SetSocketOption) in SocketExtensions.cs (breaking change but consumers of the NuGet would know).
  • Update documentation for KeepAliveTime and KeepAliveInterval to state that timeout is in seconds and take care of the difference (Socket.IOControl vs Socket.SetSocketOption) in SocketExtensions.cs .