-
Notifications
You must be signed in to change notification settings - Fork 29
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
Race Condition Prevents HTTP Server from Exiting #347
Comments
Hi @TheTechromancer , Thanks! I could reproduce your issue. Based on As a workaround you can now start the threaded server (a new feature in 1.0.11), in such case each request is served in a new thread, so stopping the server is much quicker and it is free of this mechanism. So you can try replacing the server call to this:
This worked for me. Could you also try this? This also performed much better, I think it is better to use this to serve requests made not sequentially (eg what your async code does). Zsolt |
@csernazs thanks for the quick response! After some quick testing, that workaround seems to fix the issue. This bug has caused me so much pain, you have no idea how happy this makes me lol. |
Thanks! I'm happy that I could help :) I think I'll do additional investigation on this later. pytest-httpserver uses werkzeug which then uses socketserver.py from stdlib, so as a maintainer for pytest-httpserver I rely on them to do the heavy lifting. Also, interestingly:
for i in range(100):
tasks.append(asyncio.create_task(make_request(client, httpserver.url_for("/"))))
await asyncio.sleep(10) # <--- here
print("Cancelling tasks") then this also fixes it.. So there will be definitely a race condition.. |
Hi, first off thanks for making this library; it's very useful :)
For some time now, I've been running into an elusive race condition that prevents the pytest process from exiting. It only happens in rare cases after cancellation of async tasks, and it's been a real pain to track down.
At first I thought it was a race condition in httpx, since I've discovered similar bugs in the past. But in this case, the issue seems to be specific to
pytest-httpserver
.Here is the code to reproduce:
This should produce an
httpx.ReadTimeout
error, and the httpserver should fail to exit. I've tested in on Linux, Python 3.9-3.12.Thanks!
The text was updated successfully, but these errors were encountered: