Skip to content

Misleading exception when a replication connection is aborted due to server shutdown. #5752

Description

@Brar

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.

Activity

  1. added this to the 8.0.4 milestone on Jun 15, 2024
  2. self-assigned this
    on Jun 15, 2024
  3. modified the milestones: 8.0.4, Backlog on Sep 6, 2024
  4. willibrandon commented on Sep 14, 2024

    @willibrandon

    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.

  5. added theissue type on Jun 14, 2025
  6. Brar commented on Oct 25, 2026

    @Brar
    MemberAuthor

    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.

  7. modified the milestones: Backlog, 11.0.0 on Oct 25, 2026
  8. modified the milestones: 11.0.0, 12.0.0 on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions