csernazs/pytest-httpserver

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

handrews opened this issue · 11 comments

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.

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.

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).

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.

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

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?)

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

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 commented

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

@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.

@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.

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.