2
0

Map io.EOF errors to io.ErrUnexpectedEOF

io.EOF is never expected during valid usage. In addition, database/sql
uses io.EOF as a sentinal value that all rows from a query have been
received.

See https://github.com/jackc/pgx/issues/662.
This commit is contained in:
Jack Christensen
2020-01-17 16:55:05 -06:00
parent eca1e51822
commit 595780be0f
4 changed files with 44 additions and 4 deletions
+9 -2
View File
@@ -58,12 +58,19 @@ func (f *Frontend) Send(msg FrontendMessage) error {
return err
}
func translateEOFtoErrUnexpectedEOF(err error) error {
if err == io.EOF {
return io.ErrUnexpectedEOF
}
return err
}
// Receive receives a message from the backend.
func (f *Frontend) Receive() (BackendMessage, error) {
if !f.partialMsg {
header, err := f.cr.Next(5)
if err != nil {
return nil, err
return nil, translateEOFtoErrUnexpectedEOF(err)
}
f.msgType = header[0]
@@ -73,7 +80,7 @@ func (f *Frontend) Receive() (BackendMessage, error) {
msgBody, err := f.cr.Next(f.bodyLen)
if err != nil {
return nil, err
return nil, translateEOFtoErrUnexpectedEOF(err)
}
f.partialMsg = false