When a Connection object is set up to use AMQPS, the underlying TcpTransport uses an SslStream for the TCP communication. The SslStream wraps a NetworkStream, and is correctly set up so that disposing the SslStream also disposes the NetworkStream. However, the NetworkStream is set up using only the Socket object as a constructor argument. The single parameter constructor of NetworkStream means that the NetworkStream does not own the Socket object, and so disposing the NetworkStream does not close the Socket. To properly close the Socket, and the corresponding TCP connection, the constructor on this line should be new NetworkStream(socket, true) instead of new NetworkStream(socket).
When a
Connection
object is set up to use AMQPS, the underlyingTcpTransport
uses anSslStream
for the TCP communication. TheSslStream
wraps aNetworkStream
, and is correctly set up so that disposing theSslStream
also disposes theNetworkStream
. However, theNetworkStream
is set up using only theSocket
object as a constructor argument. The single parameter constructor ofNetworkStream
means that theNetworkStream
does not own theSocket
object, and so disposing theNetworkStream
does not close theSocket
. To properly close theSocket
, and the corresponding TCP connection, the constructor on this line should benew NetworkStream(socket, true)
instead ofnew NetworkStream(socket)
.