Skip to content

Commit 63309a6

Browse files
author
Alexandru Scvortov
committed
merge bug24650 into default (Socket closed multiple times with missed heartbeat)
2 parents 972f0e2 + 9436c70 commit 63309a6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,10 @@ public void HeartbeatReadLoop()
550550
// Has to miss two full heartbeats to force socket close
551551
if (m_missedHeartbeats > 1)
552552
{
553-
EndOfStreamException eose = new EndOfStreamException(
554-
"Heartbeat missing with heartbeat == " +
555-
m_heartbeat + " seconds");
553+
String description = "Heartbeat missing with heartbeat == " +
554+
m_heartbeat + " seconds";
555+
EndOfStreamException eose = new EndOfStreamException(description);
556+
m_shutdownReport.Add(new ShutdownReportEntry(description, eose));
556557
HandleMainLoopException(new ShutdownEventArgs(
557558
ShutdownInitiator.Library,
558559
0,

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class SocketFrameHandler_0_9 : IFrameHandler
5959
public TcpClient m_socket;
6060
public NetworkBinaryReader m_reader;
6161
public NetworkBinaryWriter m_writer;
62+
private bool m_closed = false;
63+
private Object m_semaphore = new object();
6264

6365
public SocketFrameHandler_0_9(AmqpTcpEndpoint endpoint)
6466
{
@@ -150,8 +152,15 @@ public void WriteFrame(Frame frame)
150152

151153
public void Close()
152154
{
153-
m_socket.LingerState = new LingerOption(true, SOCKET_CLOSING_TIMEOUT);
154-
m_socket.Close();
155+
lock (m_semaphore)
156+
{
157+
if (!m_closed)
158+
{
159+
m_socket.LingerState = new LingerOption(true, SOCKET_CLOSING_TIMEOUT);
160+
m_socket.Close();
161+
m_closed = true;
162+
}
163+
}
155164
}
156165
}
157166
}

0 commit comments

Comments
 (0)