-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return ErrBusyBuffer instead of driver.ErrBadConn #611
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,11 +259,9 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error { | |
} | ||
|
||
// Calculate packet length and get buffer with that size | ||
data := mc.buf.takeSmallBuffer(pktLen + 4) | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
data, err := mc.buf.takeSmallBuffer(pktLen + 4) | ||
if err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example here it should be impossible that we're in a transaction with unread rows. Here the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had some time to sort things out, I think that's correct behaviour to return And only two functions So we should return What do you think? |
||
} | ||
|
||
// ClientFlags [32 bit] | ||
|
@@ -345,11 +343,9 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error { | |
|
||
// Calculate the packet length and add a tailing 0 | ||
pktLen := len(scrambleBuff) + 1 | ||
data := mc.buf.takeSmallBuffer(4 + pktLen) | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
data, err := mc.buf.takeSmallBuffer(4 + pktLen) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Add the scrambled password [null terminated string] | ||
|
@@ -364,11 +360,9 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error { | |
func (mc *mysqlConn) writeClearAuthPacket() error { | ||
// Calculate the packet length and add a tailing 0 | ||
pktLen := len(mc.cfg.Passwd) + 1 | ||
data := mc.buf.takeSmallBuffer(4 + pktLen) | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
data, err := mc.buf.takeSmallBuffer(4 + pktLen) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Add the clear password [null terminated string] | ||
|
@@ -385,11 +379,9 @@ func (mc *mysqlConn) writeNativeAuthPacket(cipher []byte) error { | |
|
||
// Calculate the packet length and add a tailing 0 | ||
pktLen := len(scrambleBuff) | ||
data := mc.buf.takeSmallBuffer(4 + pktLen) | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
data, err := mc.buf.takeSmallBuffer(4 + pktLen) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Add the scramble | ||
|
@@ -406,11 +398,9 @@ func (mc *mysqlConn) writeCommandPacket(command byte) error { | |
// Reset Packet Sequence | ||
mc.sequence = 0 | ||
|
||
data := mc.buf.takeSmallBuffer(4 + 1) | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
data, err := mc.buf.takeSmallBuffer(4 + 1) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Add command byte | ||
|
@@ -425,11 +415,9 @@ func (mc *mysqlConn) writeCommandPacketStr(command byte, arg string) error { | |
mc.sequence = 0 | ||
|
||
pktLen := 1 + len(arg) | ||
data := mc.buf.takeBuffer(pktLen + 4) | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
data, err := mc.buf.takeBuffer(pktLen + 4) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Add command byte | ||
|
@@ -446,11 +434,9 @@ func (mc *mysqlConn) writeCommandPacketUint32(command byte, arg uint32) error { | |
// Reset Packet Sequence | ||
mc.sequence = 0 | ||
|
||
data := mc.buf.takeSmallBuffer(4 + 1 + 4) | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
data, err := mc.buf.takeSmallBuffer(4 + 1 + 4) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Add command byte | ||
|
@@ -907,16 +893,15 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { | |
mc.sequence = 0 | ||
|
||
var data []byte | ||
var err error | ||
|
||
if len(args) == 0 { | ||
data = mc.buf.takeBuffer(minPktLen) | ||
data, err = mc.buf.takeBuffer(minPktLen) | ||
} else { | ||
data = mc.buf.takeCompleteBuffer() | ||
data, err = mc.buf.takeCompleteBuffer() | ||
} | ||
if data == nil { | ||
// can not take the buffer. Something must be wrong with the connection | ||
errLog.Print(ErrBusyBuffer) | ||
return driver.ErrBadConn | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// command [1 byte] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not return the error here. Leave the buffer unchanged.
This specific error should only be returned when we know that it is this specific error.