-
Notifications
You must be signed in to change notification settings - Fork 578
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
Possible race condition in RecursiveStrategy
#2717
Comments
I've only just glanced at this, but would it make more sense to change |
We've already moved 'dynamic variables' (e.g. the current settings) to thread-locals, so that makes sense to me. My main concern is whether this - even if we e.g. add |
Thank you for your feedback! My initial idea was to isolate that block from multithreaded access at all in a more defensive way - as far as I see, calling Therefore I thought that having a lock will prevent race conditions in this exact use-case. However, I am not sure whether it causes deadlocks or not (the example above worked with a lock). I will check this and try to get more details on which approach might work better. |
Hi!
I found a race condition when multiple tests share the same
RecursiveStrategy
instance and are executed in multiple threads.An example:
When running this sample with
pytest
, the following error occurs (traceback trimmed):It happens because drawing from that shared strategy in one thread changes the shared state (
currently_capped
toTrue
in thelimited_base
attribute) and if another thread draws from the same strategy while another one is still inside theself.limited_base.capped
ctx manager it fails withAssertionError
.Some time ago, I reported a race condition in #2433, and this issue comes from the same use case - Schemathesis running with multiple workers (reported here - schemathesis/schemathesis#860).
The fix is straightforward - a lock inside
RecursiveStrategy.do_draw
- I can submit a patch that fixes it.Let me know what do you think :)
The text was updated successfully, but these errors were encountered: