-
Notifications
You must be signed in to change notification settings - Fork 388
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
Fix ResourceWarning unclosed socket and re-enable and fix tornado tests #801
Fix ResourceWarning unclosed socket and re-enable and fix tornado tests #801
Conversation
This PR fixes issue kevin1024#710 by properly closing the underlying socket. It first uses `pool._put_conn` to keep the connection in the pool, and later removes and closes it when the context manager exits. I was unsure about the exact purpose of the `ConnectonRemove` class, so I made minimal changes to minimize the risk of breaking the code and there may be better solutions for fixing this issue. For example, the `urllib3.connectionpool.HTTPConnectionPool` will utilize a weakref to terminate pool connections. By appending our connection to it, it will also take care of closing our connection. So another solution could be to modify the `__exit__` in `patch.ConnectionRemover` method and add our connection to the pool: ```py class ConnectionRemover: ... def __exit__(self, *args): for pool, connections in self._connection_pool_to_connections.items(): for connection in connections: if isinstance(connection, self._connection_class): pool._put_conn(connection) ```
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #801 +/- ##
==========================================
- Coverage 90.13% 89.63% -0.51%
==========================================
Files 27 27
Lines 1815 1813 -2
Branches 336 282 -54
==========================================
- Hits 1636 1625 -11
- Misses 134 142 +8
- Partials 45 46 +1 ☔ View full report in Codecov by Sentry. |
@@ -260,6 +259,12 @@ def test_aiohttp_test_client_json(aiohttp_client, tmpdir): | |||
assert cassette.play_count == 1 | |||
|
|||
|
|||
def test_cleanup_from_pytest_asyncio(): | |||
# work around https://github.com/pytest-dev/pytest-asyncio/issues/724 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@graingert please, rebase your branch with master. |
2924107
to
b7f6c2f
Compare
@jairhenrique thanks! Turns out the tornado tests were not running, but thanks to filterwarnings=error I have discovered this and fixed it. |
'''ignore:There is no current event loop:DeprecationWarning''', | ||
'''ignore:make_current is deprecated; start the event loop first:DeprecationWarning''', | ||
'''ignore:clear_current is deprecated:DeprecationWarning''', | ||
'''ignore:the \(type, exc, tb\) signature of throw\(\) is deprecated, use the single-arg signature instead.:DeprecationWarning''', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix these deprecation warnings in a followup PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.