Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ func newBuffer(nc net.Conn) buffer {
}
}

// discard trims b.buf[:b.idx] to prohibit it reused.
//
// This is required by Rows.Close().
// See https://github.com/golang/go/commit/651ddbdb5056ded455f47f9c494c67b389622a47
func (b *buffer) discard() {
if len(b.buf)-b.idx >= defaultBufSize {
b.buf = b.buf[b.idx:]
b.idx = 0
return
}

bufSize := defaultBufSize
if bufSize < b.length {
bufSize = b.length
}
newBuf := make([]byte, bufSize)
copy(newBuf, b.buf[b.idx:b.idx+b.length])
b.buf = newBuf
b.idx = 0
}

// fill reads into the buffer until at least _need_ bytes are in it
func (b *buffer) fill(need int) error {
n := b.length
Expand Down
4 changes: 4 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (rows *mysqlRows) Close() (err error) {
return err
}

// We can't reuse receive buffer when rows.Close() is called.
// See https://github.com/golang/go/commit/651ddbdb5056ded455f47f9c494c67b389622a47
mc.buf.discard()

// Remove unread packets from stream
if !rows.rs.done {
err = mc.readUntilEOF()
Expand Down