feat: Add experimental async transport (port of PR #4572) #5646
5 issues
find-bugs: Found 5 issues (3 medium, 2 low)
Medium
close_async() silently returns without cleanup when used with non-async transport - `sentry_sdk/client.py:1066-1073`
When close_async() is called with a non-async (sync) transport, it logs a debug message and returns early without calling _close_components() or transport.kill(). This means components like session_flusher, log_batcher, metrics_batcher, span_batcher, and monitor are never killed, leaving background threads running. While the docstring says to use close() instead, returning silently without cleanup can cause resource leaks if the user mistakenly calls close_async().
Also found at:
tests/integrations/asyncio/test_asyncio.py:665-673
Race condition in rate limiting test may cause intermittent failures - `tests/test_transport.py:1121-1122`
The test test_async_transport_rate_limiting_with_concurrency at line 1122 asserts that rate limiting is enabled (_check_disabled("error") is True) after sending a message and sleeping for 0.1 seconds. However, in async context, the message goes through an async queue and network request. Under load or slow CI conditions, 0.1 seconds may not be enough for the request to complete and update the rate limit state, causing intermittent test failures.
httpcore[asyncio] dependency breaks Python 3.6/3.7 test environments - `tox.ini:340`
The common: httpcore[asyncio] dependency on line 340 applies to all Python versions in the common test environment, but httpcore requires Python 3.8+. This will cause installation failures for py3.6-common and py3.7-common test environments. The dependency should be version-gated like other version-specific dependencies (e.g., {py3.8,py3.9,...}-common: httpcore[asyncio]).
Low
Async client resources leak if test assertions fail before close_async() - `tests/test_client.py:1808-1817`
The test creates an AsyncHttpTransport client but only calls await client.close_async() at the very end of the test. If any assertion fails before reaching this line, the async connection pool (httpcore.AsyncConnectionPool or proxy variants) and the AsyncWorker task will not be properly closed. This can lead to resource warnings, connection leaks, and potentially flaky test behavior when running the test suite.
Also found at:
tests/test_transport.py:1089
Missing space in assertion error message causes unreadable output on test failure - `tests/test_client.py:1918-1919`
The f-string concatenation on lines 1918-1919 lacks a space between the two strings. When the test fails, the error message will display as 'SOCKS == Truebut got' or 'SOCKS == Falsebut got' instead of the intended 'SOCKS == True but got'. This makes test failure diagnosis harder. The same bug exists in the original sync test (test_socks_proxy).
Duration: 16m 9s · Tokens: 10.9M in / 71.4k out · Cost: $14.85 (+extraction: $0.02, +merge: $0.00, +fix_gate: $0.02)
Annotations
Check warning on line 1073 in sentry_sdk/client.py
sentry-warden / warden: find-bugs
close_async() silently returns without cleanup when used with non-async transport
When `close_async()` is called with a non-async (sync) transport, it logs a debug message and returns early without calling `_close_components()` or `transport.kill()`. This means components like session_flusher, log_batcher, metrics_batcher, span_batcher, and monitor are never killed, leaving background threads running. While the docstring says to use `close()` instead, returning silently without cleanup can cause resource leaks if the user mistakenly calls `close_async()`.
Check warning on line 673 in tests/integrations/asyncio/test_asyncio.py
sentry-warden / warden: find-bugs
[M74-J3U] close_async() silently returns without cleanup when used with non-async transport (additional location)
When `close_async()` is called with a non-async (sync) transport, it logs a debug message and returns early without calling `_close_components()` or `transport.kill()`. This means components like session_flusher, log_batcher, metrics_batcher, span_batcher, and monitor are never killed, leaving background threads running. While the docstring says to use `close()` instead, returning silently without cleanup can cause resource leaks if the user mistakenly calls `close_async()`.
Check warning on line 1122 in tests/test_transport.py
sentry-warden / warden: find-bugs
Race condition in rate limiting test may cause intermittent failures
The test `test_async_transport_rate_limiting_with_concurrency` at line 1122 asserts that rate limiting is enabled (`_check_disabled("error") is True`) after sending a message and sleeping for 0.1 seconds. However, in async context, the message goes through an async queue and network request. Under load or slow CI conditions, 0.1 seconds may not be enough for the request to complete and update the rate limit state, causing intermittent test failures.
Check warning on line 340 in tox.ini
sentry-warden / warden: find-bugs
httpcore[asyncio] dependency breaks Python 3.6/3.7 test environments
The `common: httpcore[asyncio]` dependency on line 340 applies to all Python versions in the common test environment, but httpcore requires Python 3.8+. This will cause installation failures for py3.6-common and py3.7-common test environments. The dependency should be version-gated like other version-specific dependencies (e.g., `{py3.8,py3.9,...}-common: httpcore[asyncio]`).