Skip to content

Make Npgsql 100% reliable in the face of accidental concurrent use #3701

Description

@roji

Like other ADO.NET providers, Npgsql does not allow using the same connection concurrently - doing so is a user bug. Npgsql does have some concurrency detection protection (where we throw NpgsqlOperationInProgressException with relevant information), but it's incomplete; so over the years we've received quite a few issues where users got random undefined behavior, and needed to spent quite some time tracking down the bug etc.

Ideally, Npgsql would be 100% reliable, always throwing NpgsqlOperationInProgressException; this would both help our users, and save us time analyzing issues around undefined behavior.

Some notes:

  • Opening and closing specifically isn't protected at the moment (a bit tricky since at NpgsqlConnection.Open there's no NpgsqlConnector yet to lock on, etc.)
  • We're probably not 100% tight around concurrency with the keepalives we generate; this would be a real Npgsql bug rather than a user bug - but it seems related enough.

Related issues:

Activity

  1. added this to the 6.0.0 milestone on Apr 30, 2021
  2. modified the milestones: 6.0.0, 7.0.0 on Oct 1, 2021
  3. modified the milestones: 7.0.0, Backlog on Sep 11, 2022
  4. wkwiecien-fp commented on Nov 8, 2023

    @wkwiecien-fp
  5. roji commented on Nov 8, 2023

    @roji
    Author
  6. added theissue type on Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions