Skip to content

Fix import of HTTP/1.1 connection causing thread-safety bug on 3.9 - #237

Merged
florimondmanca merged 2 commits into
masterfrom
fm/h11-3.9-partial-import
Nov 20, 2020
Merged

florimondmanca merged 2 commits into
masterfrom
fm/h11-3.9-partial-import

Conversation

@florimondmanca

@florimondmanca florimondmanca commented Nov 20, 2020 •

Copy link
Copy Markdown
Contributor

Fixes encode/httpx#1393

Moves the local import of the HTTP/1.1 connection class to a global one. It wasn't necessary (h11 is always installed), and it's a non-threadsafe trick which started causing ImportError on Python 3.9 (that it worked in 3.8 and before was actually considered as a bug: https://bugs.python.org/issue35943).

Also adds a basic test case to verify that httpcore.SyncConnectionPool can indeed be used in thread-concurrent environments.

Local testing showed that this is not a problem for h2, so keeping that local import as-is for now.

cc @senpos

@florimondmanca florimondmanca added the bug Something isn't working label Nov 20, 2020
@florimondmanca
florimondmanca requested a review from a team November 20, 2020 08:58

@euri10 euri10 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

very interesting, wasn't aware of this local / non-thread safe thing

@cdeler cdeler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great PR, you rock 🚀

Comment thread tests/test_threadsafety.py
@florimondmanca
florimondmanca merged commit 0fce6d3 into master Nov 20, 2020
@florimondmanca
florimondmanca deleted the fm/h11-3.9-partial-import branch November 20, 2020 11:47
@florimondmanca florimondmanca mentioned this pull request Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Development

Successfully merging this pull request may close these issues.

SyncHTTP11Connection ImportError on Python 3.9 when using ThreadPoolExecutor

4 participants