Skip to content

Fix teardown NRE/ODE in ReplicationConnection's SendStatusUpdate - #6630

Merged
Brar merged 1 commit into
npgsql:mainfrom
Hawxy:fix-replication-feedback-teardown-race
Oct 25, 2026
Merged

Brar merged 1 commit into
npgsql:mainfrom
Hawxy:fix-replication-feedback-teardown-race

Conversation

@Hawxy

@Hawxy Hawxy commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

If the replication connection gets torn down whilst SendStatusUpdate is in-flight, you get to spin the wheel on getting an NRE or ODE which isn't ideal:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Npgsql.Replication.ReplicationConnection.SendFeedback(Boolean waitOnSemaphore, Boolean requestReply, CancellationToken cancellationToken)
   at Npgsql.Replication.ReplicationConnection.SendStatusUpdate(CancellationToken cancellationToken)

This fixes it so OperationCanceledException and InvalidOperationException are the only exceptions that show up and should match developer expectations a bit better.

@Hawxy
Hawxy requested review from Brar, roji and vonzshik as code owners August 11, 2026 15:45

@Brar Brar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Brar Brar closed this Oct 25, 2026
@Brar Brar reopened this Oct 25, 2026
@Brar
Brar merged commit 75a8b40 into npgsql:main Oct 25, 2026
13 checks passed
@Hawxy
Hawxy deleted the fix-replication-feedback-teardown-race branch October 25, 2026 16:08
Brar added a commit to Brar/npgsql that referenced this pull request Oct 25, 2026
SendStatusUpdate_racing_replication_teardown_throws_InvalidOperationException,
which npgsql#6630 added, cancels a replication stream and starts the next one
on the same connection, ten times. Servers before PostgreSQL 10 ignore
cancellation requests on replication connections, so there Npgsql can
only cancel the stream by breaking the connection, and the test failed
with "Connection is not open" when it started the second stream. It now
requires PostgreSQL 10. This is a test-only gate for npgsql#6630's test, so
npgsql#6630 itself stays unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants