Skip to content

Commit f279100

Browse files
author
Emile Joubert
committed
Merge bug21201 into default
2 parents 49c6ae4 + bb454a3 commit f279100

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
//---------------------------------------------------------------------------
5757
using System;
5858
using System.IO;
59+
using System.Net.Sockets;
5960
using System.Text;
6061
using System.Threading;
6162
using System.Collections;
@@ -511,9 +512,9 @@ public void TerminateMainloop()
511512

512513
public void StartMainLoop()
513514
{
514-
Thread mainloopThread = new Thread(new ThreadStart(MainLoop));
515-
mainloopThread.Name = "AMQP Connection " + Endpoint.ToString();
516-
mainloopThread.Start();
515+
Thread mainLoopThread = new Thread(new ThreadStart(MainLoop));
516+
mainLoopThread.Name = "AMQP Connection " + Endpoint.ToString();
517+
mainLoopThread.Start();
517518
}
518519

519520
public void StartHeartbeatLoops()
@@ -619,6 +620,14 @@ public void MainLoop()
619620
{
620621
shutdownCleanly = HardProtocolExceptionHandler(hpe);
621622
}
623+
catch (SocketException se)
624+
{
625+
// Possibly due to handshake timeout
626+
HandleMainLoopException(new ShutdownEventArgs(ShutdownInitiator.Library,
627+
0,
628+
"Socket exception",
629+
se));
630+
}
622631
catch (Exception ex)
623632
{
624633
HandleMainLoopException(new ShutdownEventArgs(ShutdownInitiator.Library,
@@ -650,7 +659,7 @@ public void MainLoopIteration()
650659
// counter.
651660
return;
652661
}
653-
662+
654663
if (frame.Channel == 0) {
655664
// In theory, we could get non-connection.close-ok
656665
// frames here while we're quiescing (m_closeReason !=
@@ -986,7 +995,7 @@ public void Open(bool insist)
986995
m_clientProperties = new Hashtable(m_factory.ClientProperties);
987996

988997
// FIXME: check that PLAIN is supported.
989-
// FIXME: parse out locales properly!
998+
// FIXME: parse out locales properly!
990999
ConnectionTuneDetails connectionTune = default(ConnectionTuneDetails);
9911000
try
9921001
{

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
//---------------------------------------------------------------------------
5757
using System;
5858
using System.IO;
59+
using System.Net.Sockets;
5960

6061
using RabbitMQ.Util;
6162
using RabbitMQ.Client.Exceptions;
@@ -103,7 +104,21 @@ public static Frame ReadFrom(NetworkBinaryReader reader)
103104
int type;
104105
int channel;
105106

106-
type = reader.ReadByte();
107+
try
108+
{
109+
type = reader.ReadByte();
110+
}
111+
catch (IOException ioe)
112+
{
113+
// If it's a WSAETIMEDOUT SocketException, unwrap it.
114+
// This might happen when the limit of half-open connections is
115+
// reached.
116+
if (ioe.InnerException == null ||
117+
!(ioe.InnerException is SocketException) ||
118+
((SocketException)ioe.InnerException).SocketErrorCode != SocketError.TimedOut)
119+
throw ioe;
120+
throw ioe.InnerException;
121+
}
107122

108123
if (type == 'A')
109124
{
@@ -177,11 +192,11 @@ public void FinishWriting()
177192
public void WriteTo(NetworkBinaryWriter writer)
178193
{
179194
FinishWriting();
180-
writer.Write((byte)m_type);
181-
writer.Write((ushort)m_channel);
182-
writer.Write((uint)m_payload.Length);
183-
writer.Write((byte[])m_payload);
184-
writer.Write((byte)CommonFraming.Constants.FrameEnd);
195+
writer.Write((byte) m_type);
196+
writer.Write((ushort) m_channel);
197+
writer.Write((uint) m_payload.Length);
198+
writer.Write((byte[]) m_payload);
199+
writer.Write((byte) CommonFraming.Constants.FrameEnd);
185200
}
186201

187202
public NetworkBinaryReader GetReader()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Frame ReadFrame()
131131
{
132132
lock (m_reader)
133133
{
134-
return Frame.ReadFrom(m_reader);
134+
return Frame.ReadFrom(m_reader);
135135
}
136136
}
137137

0 commit comments

Comments
 (0)