Skip to content
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

Increase KEEP_ALIVE_TIMEOUT default to 120 seconds #2670

Merged
merged 4 commits into from Jul 12, 2023
Merged

Conversation

Tronic
Copy link
Member

@Tronic Tronic commented Feb 1, 2023

Sanic has used 5 second timeout to quickly close idle connections, for no particular reason, as idle connections use very little resources. This PR increases it to 80 seconds, slightly larger than Nginx default of 75 s, to avoid a problem with a request failing when Sanic has closed the connection but Nginx hasn't noticed. This should also improve practical performance on long latency connections, where reconnecting is expensive, and better fits typical user flow browsing pages with longer-than-5-second intervals.

The root cause of the next request failing (i.e. connection not being properly terminated) should be looked at in more detail, but meanwhile this should be a useful workaround to keep the defaults working fluently, as well as to improve performance for the aforementioned reasons.

Fix #2681

Sanic has used 5 second timeout to quickly close idle connections, for no particular reason, as idle connections use very little resources. This PR increases it to 80 seconds, slightly larger than Nginx default of 75 s, to avoid a problem with a request failing when Sanic has closed the connection but Nginx hasn't noticed. This should also improve practical performance on long latency connections, where reconnecting is expensive, and better fits typical user flow browsing pages with longer-than-5-second intervals.

The root cause of the next request failing (i.e. connection not being properly terminated) should be looked at in more detail, but meanwhile this should be a useful workaround to keep the defaults working fluently, as well as to improve performance for the aforementioned reasons.
@Tronic Tronic marked this pull request as ready for review February 1, 2023 16:17
@Tronic Tronic requested a review from a team as a code owner February 1, 2023 16:17
@codecov
Copy link

codecov bot commented Feb 1, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.057 🎉

Comparison is base (6848ff2) 88.887% compared to head (a14277e) 88.944%.

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2670       +/-   ##
=============================================
+ Coverage   88.887%   88.944%   +0.057%     
=============================================
  Files           92        92               
  Lines         7001      7001               
  Branches      1194      1194               
=============================================
+ Hits          6223      6227        +4     
+ Misses         531       529        -2     
+ Partials       247       245        -2     
Impacted Files Coverage Δ
sanic/config.py 97.419% <ø> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ahopkins
Copy link
Member

ahopkins commented Feb 1, 2023

Tackle timeout overhaul in June?

@Tronic
Copy link
Member Author

Tronic commented Feb 1, 2023

Yes, sounds good. This could be included as a workaround in 23.3 but probably better to avoid the hassle (docs update, release notes etc) and simply do it in 23.6 in one go with the simpler timeouts.

@Tronic Tronic closed this Feb 1, 2023
@Tronic Tronic reopened this Jul 11, 2023
@Tronic
Copy link
Member Author

Tronic commented Jul 11, 2023

Reopening for inclusion in 23.6 because we didn't get to do the bigger timeout revamping yet.

@Tronic Tronic changed the title Increase KEEP_ALIVE_TIMEOUT default to 80 seconds Increase KEEP_ALIVE_TIMEOUT default to 120 seconds Jul 11, 2023
sanic/config.py Outdated Show resolved Hide resolved
@ahopkins ahopkins merged commit 6e61eab into main Jul 12, 2023
27 checks passed
@ahopkins ahopkins deleted the stay-alive branch July 12, 2023 05:45
@nuxion nuxion mentioned this pull request Jul 13, 2023
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.

Send keep-alive header and increase the default timeout
2 participants