Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional check for concurrent usage errors #989

Merged
merged 5 commits into from
Nov 27, 2023

Conversation

robsdedude
Copy link
Member

Some driver objects (e.g, Sessions, Transactions, Result streams) are not safe for concurrent use. By default, it will cause hard to interpret errors or, in the worst case, wrong behavior.

To aid finding such bugs, the driver now detects if the Python interpreter is running development mode and enables extra locking around those objects. If they are used concurrently, an error will be raised. The way this is implemented, it will only cause a one-time overhead when loading the driver's modules if the checks are disabled.

Obviously, those checks are somewhat expensive as they entail locks (less so in the async driver). Therefore, the checks are only happening if either

  • Python is started in development mode (python -X dev ...) or
  • The environment variable PYTHONNEO4JDEBUG is set (to anything non-empty) at the time the driver's modules is loaded.

Some driver objects (e.g, Sessions, Transactions, Result streams) are not safe
for concurrent use. By default, it will cause hard to interpret errors or, in
the worst case, wrong behavior.

To aid finding such bugs, the driver now detects if the Python interpreter is
running development mode and enables extra locking around those objects. If they
are used concurrently, an error will be raised. The way this is implemented, it
will only cause a one-time overhead when loading the driver's modules if the
checks are disabled.

Obviously, those checks are somewhat expensive as they entail locks (less so in
the async driver). Therefore, the checks are only happening if either
 * Python is started in development mode (`python -X dev ...`) or
 * The environment variable `PYTHONNEO4JDEBUG` is set (to anything non-empty)
   at the time the driver's modules is loaded.
Copy link

@AndyHeap-NeoTech AndyHeap-NeoTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very cool stuff. I'm thinking something similar in other drivers for debug modes might be something we should do.

@robsdedude robsdedude merged commit d130b9c into neo4j:5.0 Nov 27, 2023
@robsdedude robsdedude deleted the debug-concurrency-check branch November 27, 2023 14:00
robsdedude added a commit to robsdedude/neo4j-python-driver that referenced this pull request Sep 25, 2024
The concurrency check introduced in
neo4j#989
introduced classmethods to several driver primitives that had the check added.
These class methods are only meant for internal use and are undocumented.
Therefore, they should be marked private.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants