Skip to content

Timeout and cancellation for COPY operations #1328

Closed

Description

@roji

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)

Activity

  1. added this to the Backlog milestone on Jun 8, 2018
  2. modified the milestones: Backlog, 5.0 on Jul 10, 2020
  3. changed the title [-]Allow setting socket send/receive timeout for COPY operations[/-] [+]Allow setting timeout for COPY operations[/+] on Sep 17, 2020
  4. roji commented on Sep 17, 2020

    @roji
    MemberAuthor

    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.

  5. vonzshik commented on Sep 17, 2020

    @vonzshik
    Contributor

    @roji sure, it should be easy to implement

  6. changed the title [-]Allow setting timeout for COPY operations[/-] [+]Timeout and cancellation for COPY operations[/+] on Oct 21, 2020
  7. roji commented on Oct 21, 2020

    @roji
    MemberAuthor

    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.

  8. added a commit that references this issue on Nov 10, 2020
    9fda64a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions