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

Thread hang with hypothesis>=6.0.4 on Apple M1 Pro, Mac OS 12.6.2, Python>=3.10 #217

Closed
handrews opened this issue Feb 19, 2023 · 11 comments

Comments

@handrews
Copy link

The testing library hypothesis made a threading change in release 6.0.4 to address a possible race condition.

On my Apple M1 Pro laptop, this works fine with pytest-httpserver for Python 3.7 - 3.9 (and presumably earlier but i have not checked).

On Python 3.10 and 3.11, all tests run just fine, but the process then hangs and will not exit without ctrl-C. The problem occurs with the latest version of hypothesis as well, but not with hypothesis 6.0.3.

The problem only occurs with pytest-httpserver installed (I tested the current 1.0.6 version, 1.0.0, and the last 0.x version, all of which had the problem). I will also file the bug with hypothesis in case there is an issue on their end.

I have included all environment details, code to reproduce, session logs, and relevant python -vvv output in this gist.

@handrews
Copy link
Author

Note that it is not necessary to do anything with pytest-httpserver to reproduce the bug. It just needs to be installed and noticed by pytest as a plugin.

handrews added a commit to handrews/jschon that referenced this issue Feb 19, 2023
The race condition fix for recursive() in hypothesis 6.0.4 has
broken the tests on Python 3.10 (and 3.11) due to the presence
of pytest-httpserver.  At least on an Apple M1 Pro chip.

Restrict it to 6.0.3 until the problem and solution are understood.
Note that all versions of pytest-httpserver seem to have the problem.

See the following issues on GitHub to track:

* csernazs/pytest-httpserver#217
* HypothesisWorks/hypothesis#3585
@csernazs
Copy link
Owner

hi!

Thanks for the report, I need some time to look at your gist and to understand it. I'm also not familiar with hypothesis.

I find it very strange that pytest-httpserver comes into the picture without using any fixture of it. If by any chance pytest-httpserver could start the server in a thread without any fixture use, then that's a problem.

Did you have a chance to test it on a non-apple hw? I'm courious if it is linked to the hardware in any way or not (I guess it is probably not linked).

@handrews
Copy link
Author

Thanks! There's no need to rush on my account as I can just pin hypothesis to 6.0.3 and everything works fine for me.

I do not have easy access to another machine at the moment, but the gist should have everything you need to reproduce it on any Python 3.10 installation in less than 5 minutes. Three packages (pytest, pytest-httpserver, and hypothesis), one file (included in the gist), and one run of pytest without any arguments will do it.

@handrews
Copy link
Author

And yes, it's strange that you don't need to do anything with it. That's one reason I also filed HypothesisWorks/hypothesis#3585

@csernazs
Copy link
Owner

I couldn't reproduce your issue on an AMD (Linux) system. It works fine with python 3.10 and 3.11 as well.

pytest imports the plugin to obtain the fixtures. This file gets imported:
https://github.com/csernazs/pytest-httpserver/blob/master/pytest_httpserver/pytest_plugin.py

This imports werkzeug and others. Maybe some of the imports breaking this (import threading maybe?)

@csernazs
Copy link
Owner

If I could reproduce it, I would start by removing the lines form that pytest_plugin.py and bisect it. :)

@handrews
Copy link
Author

Yeah, it could be another package - I don't even know what werkzeug does :-)

Thanks for replying so quickly and giving it a try. Let's see what the hypothesis folks say as they definitely did something with threads on their end. I've spent two days on this already (between a messed-up venv situation and the fact that a package the test wasn't using was involved, it was confusing), so I'm going to set it aside for now. But if the hypothesis folks don't get anywhere with it I'll give your ideas a try and let you know what happens.

@vlaci
Copy link

vlaci commented Feb 20, 2023

My hunch is that the issue occurs via implicit imports coming from __init__.py, not from the plugin itself.

@CharString
Copy link

CharString commented Feb 21, 2023

@csernazs Have you tried 3.10.10 and 3.11.2? I suspect it has something to do with these changes: python/cpython#100892 . They landed in 3.10.10 and 3.11.2. I can reproduce the issue on AMD with 3.10.10 where 3.10.9 passes.

@handrews
Copy link
Author

@CharString I found the issue on 3.10.10 and 3.11.2. I have just now verified that it does not appear on 3.10.9 and 3.11.1.

@csernazs Looks like python/cpython#102126 has been filed for it, so there's probably no need to keep this issue open unless you just want to remind yourself to check the other one.

@csernazs
Copy link
Owner

Thanks for the report and the research into this issue! Trying to understand the the linked issues now...

I ran it on python 3.11.1 and 3.10.9 (whatever is in nix), so that answers why I could not reproduce it.

I'm closing this now.

@csernazs csernazs closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2023
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

No branches or pull requests

4 participants