Skip to content

Comments

Add check for context cancellation in CopyInto methods for PG to PG#3958

Draft
Amogh-Bharadwaj wants to merge 1 commit intomainfrom
catch-context-cancel-copy
Draft

Add check for context cancellation in CopyInto methods for PG to PG#3958
Amogh-Bharadwaj wants to merge 1 commit intomainfrom
catch-context-cancel-copy

Conversation

@Amogh-Bharadwaj
Copy link
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.

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, closing the reader when necessary, allowing the connections to be dropped.

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.
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