Skip to content

Commit 4434636

Browse files
authored
fix: Fix infinite loop in transport (getsentry#656)
Fix getsentry#655
1 parent b7679a5 commit 4434636

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

sentry_sdk/integrations/logging.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
DEFAULT_LEVEL = logging.INFO
2525
DEFAULT_EVENT_LEVEL = logging.ERROR
2626

27-
_IGNORED_LOGGERS = set(["sentry_sdk.errors"])
27+
# Capturing events from those loggers causes recursion errors. We cannot allow
28+
# the user to unconditionally create events from those loggers under any
29+
# circumstances.
30+
#
31+
# Note: Ignoring by logger name here is better than mucking with thread-locals.
32+
# We do not necessarily know whether thread-locals work 100% correctly in the user's environment.
33+
_IGNORED_LOGGERS = set(["sentry_sdk.errors", "urllib3.connectionpool"])
2834

2935

3036
def ignore_logger(

tests/test_transport.py

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from sentry_sdk import Hub, Client, add_breadcrumb, capture_message
1010
from sentry_sdk.transport import _parse_rate_limits
11+
from sentry_sdk.integrations.logging import LoggingIntegration
1112

1213

1314
@pytest.fixture(params=[True, False])
@@ -57,6 +58,23 @@ def test_transport_works(
5758
assert any("Sending event" in record.msg for record in caplog.records) == debug
5859

5960

61+
def test_transport_infinite_loop(httpserver, request):
62+
httpserver.serve_content("ok", 200)
63+
64+
client = Client(
65+
"http://foobar@{}/123".format(httpserver.url[len("http://") :]),
66+
debug=True,
67+
# Make sure we cannot create events from our own logging
68+
integrations=[LoggingIntegration(event_level=logging.DEBUG)],
69+
)
70+
71+
with Hub(client):
72+
capture_message("hi")
73+
client.flush()
74+
75+
assert len(httpserver.requests) == 1
76+
77+
6078
NOW = datetime(2014, 6, 2)
6179

6280

0 commit comments

Comments
 (0)