8000 Add mutex/synchronization for running queries · Issue #59 · mauricio/postgresql-async · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.
This repository was archived by the owner on Dec 3, 2019. It is now read-only.
Add mutex/synchronization for running queries #59
Closed
@dylex

Description

@dylex

While normal use cases are fine assuming no other problems, if somehow multiple threads get ahold of the same Connection and try to run queries on it (which would clearly be a bug) it's possible for them to end up corrupting each other's queries. It would be nice if problems like this are caught. In particular, it seems that the window between validateQuery and setQueryPromise in each Connection.send* function is vulnerable and, unless I'm missing something, the AtomicReference isn't providing much benefit.

A quick glance suggests that setQueryPromise could check whether queryPromise is already defined (e.g., using a simple synchronized {} mutex or AtomicReference.compareAndSet) and throw the ConnectionStillRunningQueryException at that point.

Similarly, since the connection is effectively locked (with this change) during the query, there's no need for preparedStatementCounter to be atomic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0