Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout and cancellation for COPY operations #1328

Closed
roji opened this issue Oct 18, 2016 · 3 comments · Fixed by #3151
Closed

Timeout and cancellation for COPY operations #1328

roji opened this issue Oct 18, 2016 · 3 comments · Fixed by #3151
Assignees
Milestone

Comments

@roji
Copy link
Member

roji commented Oct 18, 2016

Socket timeouts can be set on NpgsqlCommand via the CommandTimeout property. However, COPY operations don't provide any API to set the timeout.

The current workaround is to execute some command before the COPY operation and set the socket timeout there.

At least for raw binary, where we expose a standard stream, it may make sense to expose timeout control via ReadTimeout and WriteTimeout (see also CanTimeout), though we need to understand whether these should work for async as well, and how things interact with async cancellation tokens.

Don't forget to populate the cancellation token in the OperationCanceledException and assert (#3252)

@roji roji added this to the Backlog milestone Jun 8, 2018
@roji roji modified the milestones: Backlog, 5.0 Jul 10, 2020
@roji roji changed the title Allow setting socket send/receive timeout for COPY operations Allow setting timeout for COPY operations Sep 17, 2020
@roji
Copy link
Member Author

roji commented Sep 17, 2020

Ideally we do both sync and async here. It would be a nice part of the new timeout story, /cc @vonzshik in case you're interested.

@vonzshik
Copy link
Contributor

@roji sure, it should be easy to implement

@roji roji changed the title Allow setting timeout for COPY operations Timeout and cancellation for COPY operations Oct 21, 2020
@roji
Copy link
Member Author

roji commented Oct 21, 2020

Notes for cancellation:

For exporting (COPY OUT), things work similar to how they work with regular commands, when results are already being streamed back. In other words, when the cancellation token is triggered we can do the same thing - attempt PG cancellation, and close the socket after CancellationTimeout.

For importing (COPY IN) things are different. Since the server is waiting for us to send stuff, we just send a CopyFail message on the main connection (no need to open a side one like with regular cancellation), and wait. We should ideally apply CancellationTimeout on the waiting period after we send CopyFail.

One interesting problem with import, is that since it doesn't open a side connection, it cannot be done concurrently. This is a problem for cancellation tokens, which are expected to be triggerable at any time (e.g. whenever the user clicks some button). A full solution here would guard against this with synchronization. But I'm not sure it's critical for 5.0.

Here are the PostgreSQL protocol docs on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants