Skip to content

Commit cec5eba

Browse files
author
Michal Drausowski
committed
Workaround panic crash when receiving terminate connection message while performing CopyFrom
1 parent 15bca4a commit cec5eba

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

pgconn/pgconn.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,14 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co
13731373
close(pgConn.cleanupDone)
13741374
return CommandTag{}, normalizeTimeoutError(ctx, err)
13751375
}
1376-
msg, _ := pgConn.receiveMessage()
1376+
// peekMessage never returns err in the bufferingReceive mode - it only forwards the bufferingReceive variables.
1377+
// Therefore, the only case for receiveMessage to return err is during handling of the ErrorResponse message type
1378+
// and using pgOnError handler to determine the connection is no longer valid (and thus closing the conn).
1379+
msg, serverError := pgConn.receiveMessage()
1380+
if serverError != nil {
1381+
close(abortCopyChan)
1382+
return CommandTag{}, serverError
1383+
}
13771384

13781385
switch msg := msg.(type) {
13791386
case *pgproto3.ErrorResponse:

0 commit comments

Comments
 (0)