Skip to content
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

error happened but not returned to the client #48446

Closed
tiancaiamao opened this issue Nov 8, 2023 · 0 comments · Fixed by #48447
Closed

error happened but not returned to the client #48446

tiancaiamao opened this issue Nov 8, 2023 · 0 comments · Fixed by #48447
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@tiancaiamao
Copy link
Contributor

tiancaiamao commented Nov 8, 2023

Enhancement

By reproduce #48411 and after reading the code, I found it might not be the only case that
error happened but not returned to the client.

defer terror.Call(rs.Close())
for {
    data = rs.Next()
    writePacket(data)
}
writeEOF()

terror.Call ignores error, so the error is not returned to the client.

But NOTE, even we to write it as this, the code is still wrong:

defer func() {
    err = rs.Close()
}()
for {
    data = rs.Next()
    writePacket(data)
}
writeEOF()

The problem is that after we writeEOF(), we finish this mysql response telling the client that all the data is done.
So even we find an error later (for example, in defer rs.Close()), there is no way to tell the mysql client any more!

The correct order should be:

for {
    data = rs.Next()
    writePacket(data)
}
if err = rs.Close(); err != nil {
    writeErr()
} else {
    writeEOF()
}
@tiancaiamao tiancaiamao added the type/enhancement The issue or PR belongs to an enhancement. label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant