Skip to content

Commit

Permalink
recycle read pool immediately to avoid panic (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
chicliz authored Nov 20, 2020
1 parent ee11efb commit 2d3303c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions mysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,14 @@ func (c *Conn) ReadEphemeralPacketDirect() ([]byte, error) {
if c.currentEphemeralPolicy != ephemeralUnused {
panic(fmt.Errorf("ReadEphemeralPacketDirect: unexpected currentEphemeralPolicy: %v", c.currentEphemeralPolicy))
}
c.currentEphemeralPolicy = ephemeralRead

var r io.Reader = c.conn

length, err := c.readHeaderFrom(r)
if err != nil {
return nil, err
}

c.currentEphemeralPolicy = ephemeralRead
if length == 0 {
// This can be caused by the packet after a packet of
// exactly size MaxPacketSize.
Expand Down
2 changes: 1 addition & 1 deletion proxy/server/client_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func (cc *ClientConn) readHandshakeResponse() (HandshakeResponseInfo, error) {
info.Salt = cc.salt

data, err := cc.ReadEphemeralPacketDirect()
defer cc.RecycleReadPacket()
if err != nil {
return info, err
}
defer cc.RecycleReadPacket()

pos := 0

Expand Down

0 comments on commit 2d3303c

Please sign in to comment.