Skip to content
Merged
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
9 changes: 9 additions & 0 deletions go/mysql/conn_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,15 @@ func (t testRun) ComQuery(c *Conn, query string, callback func(*sqltypes.Result)
if strings.Contains(query, "panic") {
panic("test panic attack!")
}
if strings.Contains(query, "close before rows read") {
c.writeFields(selectRowsResult)
// We want to close the connection after the fields are written
// and read on the client. So we sleep for 100 milliseconds
time.Sleep(100 * time.Millisecond)
c.Close()
return nil
}

if strings.Contains(query, "twice") {
callback(selectRowsResult)
}
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (c *Conn) ReadQueryResult(maxrows int, wantfields bool) (*sqltypes.Result,
for {
data, err := c.readEphemeralPacket()
if err != nil {
return nil, false, 0, err
return nil, false, 0, NewSQLError(CRServerLost, SSUnknownSQLState, "%v", err)
}

if c.isEOFPacket(data) {
Expand Down
26 changes: 26 additions & 0 deletions go/mysql/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,32 @@ func TestComStmtClose(t *testing.T) {
}
}

// This test has been added to verify that IO errors in a connection lead to SQL Server lost errors
// So that we end up closing the connection higher up the stack and not reusing it.
// This test was added in response to a panic that was run into.
func TestSQLErrorOnServerClose(t *testing.T) {
// Create socket pair for the server and client
listener, sConn, cConn := createSocketPair(t)
defer func() {
listener.Close()
sConn.Close()
cConn.Close()
}()

err := cConn.WriteComQuery("close before rows read")
require.NoError(t, err)

handler := &testRun{t: t}
_ = sConn.handleNextCommand(handler)

// From the server we will receive a field packet which the client will read
// At that point, if the server crashes and closes the connection.
// We should be getting a Connection lost error.
_, _, _, err = cConn.ReadQueryResult(100, true)
require.Error(t, err)
require.True(t, IsConnLostDuringQuery(err), err.Error())
}

func TestQueries(t *testing.T) {
listener, sConn, cConn := createSocketPair(t)
defer func() {
Expand Down