Skip to content

feat(transport): Add a timeout#4252

Merged
sentrivana merged 13 commits into
masterfrom
ivana/add-transport-timeouts
Apr 10, 2025
Merged

feat(transport): Add a timeout#4252
sentrivana merged 13 commits into
masterfrom
ivana/add-transport-timeouts

Conversation

@sentrivana

@sentrivana sentrivana commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

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.)

@codecov

codecov Bot commented Apr 8, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.53%. Comparing base (fb6d374) to head (f135ac3).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4252      +/-   ##
==========================================
- Coverage   79.54%   79.53%   -0.01%     
==========================================
  Files         142      142              
  Lines       15905    15907       +2     
  Branches     2723     2723              
==========================================
  Hits        12652    12652              
- Misses       2385     2389       +4     
+ Partials      868      866       -2     
Files with missing lines Coverage Δ
sentry_sdk/transport.py 80.04% <100.00%> (+0.09%) ⬆️

... and 6 files with indirect coverage changes

@sentrivana sentrivana linked an issue Apr 8, 2025 that may be closed by this pull request
@aivarsk

aivarsk commented Apr 8, 2025

Copy link
Copy Markdown

You missed the second pool options implementation around lines 772 for HTTP2 I guess

@aivarsk

aivarsk commented Apr 8, 2025

Copy link
Copy Markdown

And just a side note - I don't know what are the Sentry SaaS response times but 5 seconds might be too little for the read timeout. I think other software uses 15 seconds by default.

@sentrivana

sentrivana commented Apr 8, 2025

Copy link
Copy Markdown
Contributor Author

Gotcha, still working on this, not final yet -- planning on adding the timeout to the other transport and also need to decide on a good default

@sentrivana sentrivana changed the title feat(transport): Add a read/connect timeout feat(transport): Add a timeout Apr 9, 2025
@sentrivana
sentrivana marked this pull request as ready for review April 10, 2025 07:36
@sentrivana
sentrivana requested a review from a team as a code owner April 10, 2025 07:36
@sentrivana
sentrivana requested a review from a team April 10, 2025 07:37

@antonpirker antonpirker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good! 🚀

@sentrivana
sentrivana merged commit 6000f87 into master Apr 10, 2025
@sentrivana
sentrivana deleted the ivana/add-transport-timeouts branch April 10, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentry-python does not set connection timeouts

3 participants