2
0

Extend handling of unexpected EOF to the backend

In the original issue [1] and commit [2], support for unexpected EOF was
added to the frontend to detect when a connection was closed abruptly.
Additionally, this allows us to differentiate normal io.EOF errors with
unexpected errors in the backend.

[1] https://github.com/jackc/pgx/issues/662/
[2] https://github.com/jackc/pgproto3/commit/595780be0f9f581451a23a5151b77f782202ad72
This commit is contained in:
Yuli Khodorkovskiy
2021-06-30 12:54:45 -04:00
parent 7c9e840726
commit 10c6c50ac9
2 changed files with 25 additions and 3 deletions
+3 -3
View File
@@ -58,7 +58,7 @@ func (b *Backend) ReceiveStartupMessage() (FrontendMessage, error) {
buf, err = b.cr.Next(msgSize)
if err != nil {
return nil, err
return nil, translateEOFtoErrUnexpectedEOF(err)
}
code := binary.BigEndian.Uint32(buf)
@@ -98,7 +98,7 @@ func (b *Backend) Receive() (FrontendMessage, error) {
if !b.partialMsg {
header, err := b.cr.Next(5)
if err != nil {
return nil, err
return nil, translateEOFtoErrUnexpectedEOF(err)
}
b.msgType = header[0]
@@ -152,7 +152,7 @@ func (b *Backend) Receive() (FrontendMessage, error) {
msgBody, err := b.cr.Next(b.bodyLen)
if err != nil {
return nil, err
return nil, translateEOFtoErrUnexpectedEOF(err)
}
b.partialMsg = false