You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Misleading exception when a replication connection is aborted due to server shutdown. #5752
When the backend is shut down while a replication connection is connected and replicating, a CommandComplete message is issued by the server.
We currently don't expect that and throw an exception as if we had a loss of protocol sync ("Received backend message CommandComplete while expecting CopyDataMessage. Please file a bug.").
This is misleading and could make people report a bug in a rather common situation.
Do you mind me asking how you are shutting down your backend? I am looking at Npgsql replication documentation for fun and learning and would like to reproduce this issue if possible.
The same happens when a physical stream reaches the end of a timeline, e.g. after the standby we stream from was promoted. The server then ends COPY mode with CopyDone (postgres walsender.c:3552-3553), and Npgsql breaks the connection with "Received backend message CopyDone while expecting CopyDataMessage. Please file a bug." (ReplicationConnection.cs:462-463, Statics.cs:56-59). Asked to start at the end of a historic timeline, the server sends the next timeline as a result set without entering COPY mode (postgres walsender.c:983, 1045), which breaks the connection with "Received unexpected backend message RowDescription. Please file a bug." (ReplicationConnection.cs:436-446, NpgsqlConnector.cs:2253-2254).
What should happen instead: a server shutdown should throw an NpgsqlException that says the server ended the stream, and the end of a timeline should end the enumeration normally, with the connection still usable.
Activity
willibrandon commentedon Sep 14, 2024
Do you mind me asking how you are shutting down your backend? I am looking at Npgsql replication documentation for fun and learning and would like to reproduce this issue if possible.
Handle the end of a replication stream at timeline switches and shutdown
Brar commentedon Oct 25, 2026
The same happens when a physical stream reaches the end of a timeline, e.g. after the standby we stream from was promoted. The server then ends COPY mode with CopyDone (postgres
walsender.c:3552-3553), and Npgsql breaks the connection with "Received backend message CopyDone while expecting CopyDataMessage. Please file a bug." (ReplicationConnection.cs:462-463,Statics.cs:56-59). Asked to start at the end of a historic timeline, the server sends the next timeline as a result set without entering COPY mode (postgreswalsender.c:983,1045), which breaks the connection with "Received unexpected backend message RowDescription. Please file a bug." (ReplicationConnection.cs:436-446,NpgsqlConnector.cs:2253-2254).What should happen instead: a server shutdown should throw an NpgsqlException that says the server ended the stream, and the end of a timeline should end the enumeration normally, with the connection still usable.