diff --git a/src/mysql/read_packet.cr b/src/mysql/read_packet.cr index 93c01ab..6c6c653 100644 --- a/src/mysql/read_packet.cr +++ b/src/mysql/read_packet.cr @@ -6,12 +6,14 @@ class MySql::ReadPacket @seq : UInt8 def initialize(@io : IO, @connection : Connection) - header = uninitialized UInt8[4] - io.read_fully(header.to_slice) - @length = @remaining = header[0].to_i + (header[1].to_i << 8) + (header[2].to_i << 16) - @seq = header[3] - rescue IO::EOFError - raise DB::ConnectionLost.new(@connection) + begin + header = uninitialized UInt8[4] + io.read_fully(header.to_slice) + @length = @remaining = header[0].to_i + (header[1].to_i << 8) + (header[2].to_i << 16) + @seq = header[3] + rescue IO::EOFError + raise DB::ConnectionLost.new(@connection) + end end def to_s(io)