Skip to content

Deadlock can occur in a batch when executing synchronously, with very specific statements #3846

Closed

Description

@roji

When executing a batched command synchronously, we currently switch to asynchronous writing. This is to prevent a deadlock with PG, where we're stuck writing a big 2nd statement but PG is stuck writing back the results of the 1st statement.

However, we switch to async only once a flush has occurred - this is incorrect. A small 1st statement which produces a lot of results, followed by a huge 2nd statement (big parameter) would cause a deadlock, as the 2nd statement is still written synchronously (since no flush occurred).

We must switch to async writing starting with the 2nd statement, regardless of whether a flush has occurred or not. We may as well write the entire batch asynchronously, but as @vonzshik pointed out, writing the 1st statement synchronously is useful to improve the chances we get errors out.

Activity

  1. added this to the 5.0.8 milestone on Jun 16, 2021
  2. self-assigned this
    on Jun 16, 2021
  3. added a commit that references this issue on Jun 16, 2021
    991dbb4
  4. added 4 commits that reference this issue on Jun 16, 2021
    3b8034b
    56ff868
    fc36ec9
    f022fa5
  5. added theissue type on Jun 18, 2025
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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions