You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Timeout and cancellation for COPY operations #1328
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)
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.
Activity
[-]Allow setting socket send/receive timeout for COPY operations[/-][+]Allow setting timeout for COPY operations[/+]roji commentedon 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 commentedon Sep 17, 2020
@roji sure, it should be easy to implement
[-]Allow setting timeout for COPY operations[/-][+]Timeout and cancellation for COPY operations[/+]roji commentedon 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.
Added timeouts for the COPY operations