Skip to content

Commit bb454a3

Browse files
author
Emile Joubert
committed
Catch timeout safely, only on network read
1 parent 33693df commit bb454a3

File tree

1 file changed

+10
-20
lines changed
  • projects/client/RabbitMQ.Client/src/client/impl

1 file changed

+10
-20
lines changed

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ public static Frame ReadFrom(NetworkBinaryReader reader)
113113
// If it's a WSAETIMEDOUT SocketException, unwrap it.
114114
// This might happen when the limit of half-open connections is
115115
// reached.
116-
SocketException se = (SocketException) ioe.InnerException;
117-
if (se != null && se.SocketErrorCode == SocketError.TimedOut)
118-
throw se;
119-
else
120-
throw;
116+
if (ioe.InnerException == null ||
117+
!(ioe.InnerException is SocketException) ||
118+
((SocketException)ioe.InnerException).SocketErrorCode != SocketError.TimedOut)
119+
throw ioe;
120+
throw ioe.InnerException;
121121
}
122122

123123
if (type == 'A')
@@ -192,21 +192,11 @@ public void FinishWriting()
192192
public void WriteTo(NetworkBinaryWriter writer)
193193
{
194194
FinishWriting();
195-
try
196-
{
197-
writer.Write((byte) m_type);
198-
writer.Write((ushort) m_channel);
199-
writer.Write((uint) m_payload.Length);
200-
writer.Write((byte[]) m_payload);
201-
writer.Write((byte) CommonFraming.Constants.FrameEnd);
202-
}
203-
catch(IOException ioe)
204-
{
205-
if (ioe.InnerException != null)
206-
throw ioe.InnerException;
207-
else
208-
throw;
209-
}
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);
210200
}
211201

212202
public NetworkBinaryReader GetReader()

0 commit comments

Comments
 (0)