Skip to content

Commit

Permalink
Use Stream.Read instead of .ReadByte for the first byte
Browse files Browse the repository at this point in the history
It appears that on occassion ReadByte can hang unexpectedly. Maybe
Read does suffer this issue?
  • Loading branch information
HoloRin authored and lukebakken committed Feb 9, 2022
1 parent 4628927 commit 5be4196
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions projects/RabbitMQ.Client/client/impl/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 208,13 @@ internal static InboundFrame ReadFrom(Stream reader, byte[] frameHeaderBuffer)
int type = default;
try
{
type = reader.ReadByte();
byte[] buf = new byte[1];
int c = reader.Read(buf, 0, 1);
if (c == 0)
{
throw new EndOfStreamException("Reached the end of the stream. Possible authentication failure.");
}
type = buf[0];
}
catch (IOException ioe)
{
Expand All @@ -225,14 231,10 @@ internal static InboundFrame ReadFrom(Stream reader, byte[] frameHeaderBuffer)
ExceptionDispatchInfo.Capture(ioe.InnerException).Throw();
}

switch (type)
if (type == 'A')
{
case -1:
throw new EndOfStreamException("Reached the end of the stream. Possible authentication failure.");
case 'A':
// Probably an AMQP protocol header, otherwise meaningless
ProcessProtocolHeader(reader);
break;
// Probably an AMQP protocol header, otherwise meaningless
ProcessProtocolHeader(reader);
}

reader.Read(frameHeaderBuffer, 0, frameHeaderBuffer.Length);
Expand Down

0 comments on commit 5be4196

Please sign in to comment.