Skip to content

Mark connections as bad on MariaDB shutdown #451

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

Closed
wants to merge 8 commits into from
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Runrioter Wung <runrioter at gmail.com>
Soroush Pour <me at soroushjp.com>
Stan Putrya <root.vagner at gmail.com>
Stanley Gunawan <gunawan.stanley at gmail.com>
Thomas Parrott <tomp at tomp.uk>
Xiaobing Jiang <s7v7nislands at gmail.com>
Xiuming Chen <cc at cxm.cc>

Expand Down
16 changes: 15 additions & 1 deletion packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
if data[3] > mc.sequence {
return nil, ErrPktSyncMul
}
return nil, ErrPktSync

//When MariaDB server is shutdown connection killed packet is sent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a space between `// and the comment.
Slightly changed comment: "The MariaDB server sends a packet with sequence number 0 when the server is shutdown."

//with a zero sequence number.
//Continue to process it so the specific error can be detected.
if data[3] != 0 {
return nil, ErrPktSync
}
}

mc.sequence++

// Read packet body [pktLen bytes]
Expand Down Expand Up @@ -525,6 +532,13 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
pos = 9
}

//If error code is for Connection was killed, then return bad connection.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a space here and put "Connection was killed" in quotes. Maybe also replace "then return bad connection" with "then mark connection as bad"

//https://mariadb.com/kb/en/mariadb/mariadb-error-codes/
if errno == 1927 {
errLog.Print("Error ", errno, ": ", string(data[pos:]))
return driver.ErrBadConn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not safe, because we can't know this error was sent before sending query or not.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my question is assuming this came after a query is sent. is ErrPktSync a recoverable error, i.e. can i still use the connection after I get back that error from the driver ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I can't get what is your question.
Clearly, you cannot use the connection.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what is the difference between returning ErrBadConn and ErrPktSync ? The latter seem to be unrecoverable and ErrBadConn is the right way for the driver to signal to go that the connection is in a bad state

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can close this connection (mc.close() to make next call returns ErrBadConn.

}

// Error Message [string]
return &MySQLError{
Number: errno,
Expand Down