python-trio / hip

A new Python HTTP client for everybody

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix test_connection_cleanup_on_read_timeout

pquentin opened this issue · comments

So we have this failing test named test_connection_cleanup_on_read_timeout. @RatanShreshtha investigated to understand the situation. Here's the test:

https://github.com/python-trio/urllib3/blob/e8603c043894bd28809e76b0edf209fc3e062759/test/with_dummyserver/test_socketlevel.py#L551-L578

The test fails because the connection is not returned to the pool, so poolsize != pool.pool.qsize(). In the bleach-spike branch, the connection is only released when the response is complete:

https://github.com/python-trio/urllib3/blob/e8603c043894bd28809e76b0edf209fc3e062759/src/urllib3/_async/response.py#L289-L298

The response is complete when the client and server h11 states are IDLE:

https://github.com/python-trio/urllib3/blob/e8603c043894bd28809e76b0edf209fc3e062759/src/urllib3/_async/connection.py#L523-L532

This is True when the request has completed successfully, but it should be also be True when there's not a clean exit. So I think the fix is to make sure the state comes back to idle when self.close() is called.

And indeed, #72 fixes the issue, by improving upon #68. Now let's fight with CI...