Skip to content

Commit c2fee99

Browse files
author
Alexandru Scvortov
committed
remove connection close timeout and add socket close timeout
1 parent 542e4f9 commit c2fee99

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ public abstract class ConnectionBase : IConnection
6969
///complete (milliseconds)</summary>
7070
public static int HandshakeTimeout = 10000;
7171

72-
///<summary>Timeout used while waiting for a
73-
///connection.close-ok reply to a connection.close request
74-
///(milliseconds)</summary>
75-
public static int ConnectionCloseTimeout = 10000;
76-
7772
public ConnectionFactory m_factory;
7873
public IFrameHandler m_frameHandler;
7974
public uint m_frameMax = 0;
@@ -619,15 +614,14 @@ public void MainLoop()
619614
"Unexpected Exception",
620615
ex));
621616
}
622-
623-
// If allowed for clean shutdown
624-
// Run main loop for a limited amount of time (as defined
625-
// by ConnectionCloseTimeout).
617+
618+
// If allowed for clean shutdown, run main loop until the
619+
// connection closes.
626620
if (shutdownCleanly)
627621
{
628622
ClosingLoop();
629623
}
630-
624+
631625
FinishClose();
632626

633627
m_appContinuation.Set();
@@ -731,16 +725,10 @@ public void ClosingLoop()
731725
{
732726
try
733727
{
734-
m_frameHandler.Timeout = ConnectionCloseTimeout;
735-
DateTime startTimeout = DateTime.Now;
728+
m_frameHandler.Timeout = 0;
736729
// Wait for response/socket closure or timeout
737730
while (!m_closed)
738731
{
739-
if ((DateTime.Now - startTimeout).TotalMilliseconds >= ConnectionCloseTimeout)
740-
{
741-
LogCloseError("Timeout, when waiting for server's response on close", null);
742-
break;
743-
}
744732
MainLoopIteration();
745733
}
746734
}

projects/client/RabbitMQ.Client/src/client/impl/SocketFrameHandler_0_9.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ namespace RabbitMQ.Client.Impl
4949
{
5050
public class SocketFrameHandler_0_9 : IFrameHandler
5151
{
52-
public const int WSAEWOULDBLOCK = 10035;
52+
public const int WSAEWOULDBLOCK = 10035;
5353
// ^^ System.Net.Sockets.SocketError doesn't exist in .NET 1.1
5454

55+
// Timeout in seconds to wait for a clean socket close.
56+
public const int SOCKET_CLOSING_TIMEOUT = 1;
57+
5558
public AmqpTcpEndpoint m_endpoint;
5659
public TcpClient m_socket;
5760
public NetworkBinaryReader m_reader;
@@ -147,6 +150,7 @@ public void WriteFrame(Frame frame)
147150

148151
public void Close()
149152
{
153+
m_socket.LingerState = new LingerOption(true, SOCKET_CLOSING_TIMEOUT);
150154
m_socket.Close();
151155
}
152156
}

0 commit comments

Comments
 (0)