You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Establishing new client connections fail intermittently when using the library to connect against an AMQPS endpoint over IPv6 in .NET 6 (if we switch the client code back to .NET core 2.1 or connect to an IPv4 broker, the errors no longer happen).
Repro steps
Start the local test broker on an IPv6 amqps address, like the following:
This code simply opens a connection 100 times. On .NET core 2.1 this code works fine, but on .NET 6, after a few iterations, the code eventually fails with the following exception:
System.IO.IOException : Transport 'tls4' is valid for write operations.
---- System.InvalidOperationException : This operation is only allowed using a successfully authenticated context.
Investigation
After a lengthy investigation, we were able to identify the root cause of the race condition in the following call on TcpTransportInitiator.cs:44:
When this call returns true all works well, which seems to always be the case in .NET core 2.1 or when connecting to an IPv4 broker. However, when it returns false, indicating that the connection was performed synchronously, the library breaks. In .NET 6, this call seems to return false from time to time for IPv6 sockets.
More specifically, when the call above returns false, it causes the following path on AmqpTransportInitiator.cs:367 to be executed twice:
if(!thisPtr.CompleteSelf(args.CompletedSynchronously,args.Exception)){if(args.Transport!=null){// completed by timerargs.Transport.Abort();}}
The first time causes the operation to complete. The second time, however, because the operation was already completed once, causes Transport.Abort() to be called, which disposes the connection, cause the failures we see above.
The text was updated successfully, but these errors were encountered:
peolivei2
changed the title
Possible race condition when establishing connections on .NET 6
Intermittent connection failures when using AMQPS over IPv6 on .NET 6
Mar 11, 2023
Issue
Establishing new client connections fail intermittently when using the library to connect against an AMQPS endpoint over IPv6 in .NET 6 (if we switch the client code back to .NET core 2.1 or connect to an IPv4 broker, the errors no longer happen).
Repro steps
This code simply opens a connection 100 times. On .NET core 2.1 this code works fine, but on .NET 6, after a few iterations, the code eventually fails with the following exception:
Investigation
After a lengthy investigation, we were able to identify the root cause of the race condition in the following call on
TcpTransportInitiator.cs:44:
When this call returns
true
all works well, which seems to always be the case in .NET core 2.1 or when connecting to an IPv4 broker. However, when it returnsfalse
, indicating that the connection was performed synchronously, the library breaks. In .NET 6, this call seems to returnfalse
from time to time for IPv6 sockets.More specifically, when the call above returns
false
, it causes the following path on AmqpTransportInitiator.cs:367 to be executed twice:The first time causes the operation to complete. The second time, however, because the operation was already completed once, causes
Transport.Abort()
to be called, which disposes the connection, cause the failures we see above.The text was updated successfully, but these errors were encountered: