Skip to content

Sentry-python does not set connection timeouts #4247

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

Closed
aivarsk opened this issue Apr 6, 2025 · 1 comment · Fixed by #4252
Closed

Sentry-python does not set connection timeouts #4247

aivarsk opened this issue Apr 6, 2025 · 1 comment · Fixed by #4252
Labels
Component: Transport Dealing with the transport Improvement Python SDK

Comments

@aivarsk
Copy link

aivarsk commented Apr 6, 2025

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.25.1

Steps to Reproduce

When sentry-python tries to report errors during network failures, it may hang up forever while trying to connect.

Expected Result

Inside transport.py both _get_pool_options it should set timeouts to something reasonable like:

        options["timeout"] = urllib3.util.Timeout(connect=5, read=5)

That will allow process to terminate during network failures.

Actual Result

When the PoolManager is created, it gets the default timeout values (https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html#urllib3.util.Timeout)

Timeout(connect=<_TYPE_DEFAULT.token: -1>, read=<_TYPE_DEFAULT.token: -1>, total=None)

This leads to connect call being made in blocking mode and it might block forever preventing the process to terminate and restart.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 6, 2025
@sentrivana
Copy link
Contributor

Hey @aivarsk, thanks for taking the time to open this -- this would definitely be good to add. I'll take a look.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Apr 8, 2025
@sentrivana sentrivana added the Component: Transport Dealing with the transport label Apr 8, 2025
@sentrivana sentrivana linked a pull request Apr 8, 2025 that will close this issue
@linear linear bot added the Improvement label Apr 9, 2025
sentrivana added a commit that referenced this issue Apr 10, 2025
For some reason, we don't define any timeouts in our default
transport(s).

With this change:
- We add a 30s total timeout for the whole connect+read cycle in the
default HTTP transport
- In the experimental HTTP/2 httpcore-based transport there is no way to
set a single timeout, so we set 15s each for getting a connection from
the pool, connecting, writing, and reading

Backend SDKs in general set wildly different timeouts, from 30s in Go to
<5s in Ruby or PHP. I went for the higher end of the range here since
this is mainly meant to prevent the SDK preventing process shutdown like
described in #4247 --
we don't want to cut off legitimate requests that are just taking a long
time. (I was considering going even higher, maybe to 60s -- but I think
30s is a good first shot at this and we can always change it later.)
@stephanie-anderson stephanie-anderson added the Python SDK label Apr 25, 2025 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Transport Dealing with the transport Improvement Python SDK
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants