-
Notifications
You must be signed in to change notification settings - Fork 834
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
Comments
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. |
@roji sure, it should be easy to implement |
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. |
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)
The text was updated successfully, but these errors were encountered: