Skip to content

[Representational purpose only] Making connection drops work for PG to PG#3958

Draft
Amogh-Bharadwaj wants to merge 4 commits intomainfrom
catch-context-cancel-copy
Draft

[Representational purpose only] Making connection drops work for PG to PG#3958
Amogh-Bharadwaj wants to merge 4 commits intomainfrom
catch-context-cancel-copy

Conversation

@Amogh-Bharadwaj
Copy link
Copy Markdown
Contributor

@Amogh-Bharadwaj Amogh-Bharadwaj commented Feb 18, 2026

An issue was discovered recently where when a mirror running initial load from PG to PG is dropped, the copy process continues to run on source.

This PR shows an unideal reality of our use of PGX single connection reuse for syncing partitions in PG to PG initial load.
It involves replacing a lot of our commands' contexts with background contexts to bypass pgx's context watcher. It also fixes the pg_export_snapshot connection from lingering and taking a minute to be cleaned up.

An issue was discovered recently where when a mirror running initial
load from PG to PG is dropped, the copy process continues to run on
source.

A hint in pgx for CopyFrom reveals that context cancellation may not be
acted upon while the reader is still open:
```
CopyFrom executes the copy command sql and copies all of r to the
PostgreSQL server.

Note: context cancellation will only interrupt operations on the
underlying PostgreSQL network connection. Reads on r could still block.
```

This PR adds a check for context cancellation in the CopyInto methods
for PG to PG, which should allow the copy process to be interrupted
when the context is cancelled, preventing it from continuing to run
on the source when a mirror is dropped.
@Amogh-Bharadwaj Amogh-Bharadwaj force-pushed the catch-context-cancel-copy branch from ca97eca to 19cf45f Compare February 27, 2026 19:56
@Amogh-Bharadwaj Amogh-Bharadwaj changed the title Add check for context cancellation in CopyInto methods for PG to PG [Representational purpose only] Making connection drops work for PG to PG Feb 27, 2026
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