Skip to content

Set self-adjusting deadline for connection writing #16068

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

Merged
merged 11 commits into from
Jun 10, 2021

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Jun 4, 2021

In #16055 it appears that the simple 5s deadline doesn't work for large
file writes. Now we can't - or at least shouldn't just set no deadline
as go will happily let these connections block indefinitely. However,
what seems reasonable is to set some minimum rate we expect for writing.

This PR suggests the following algorithm:

  • Every write has a minimum timeout of 5s (adjustable at compile time.)
  • If there has been a previous write - then consider its previous
    deadline, add half of the minimum timeout + 2s per kb about to written.
  • If that new deadline is after the minimum timeout use that.

Fix #16055

Signed-off-by: Andrew Thornton art27@cantab.net

In go-gitea#16055 it appears that the simple 5s deadline doesn't work for large
file writes. Now we can't - or at least shouldn't just set no deadline
as go will happily let these connections block indefinitely. However,
what seems reasonable is to set some minimum rate we expect for writing.

This PR suggests the following algorithm:

* Every write has a minimum timeout of 5s (adjustable at compile time.)
* If there has been a previous write - then consider its previous
deadline, add half of the minimum timeout + 2s per kb about to written.
* If that new deadline is after the minimum timeout use that.

Fix go-gitea#16055

Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
@codecov-commenter
Copy link

codecov-commenter commented Jun 4, 2021

Codecov Report

Merging #16068 (ffcf471) into main (7979c36) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16068      +/-   ##
==========================================
- Coverage   44.06%   44.06%   -0.01%     
==========================================
  Files         682      682              
  Lines       82460    82465       +5     
==========================================
+ Hits        36338    36340       +2     
- Misses      40205    40209       +4     
+ Partials     5917     5916       -1     
Impacted Files Coverage Δ
modules/graceful/server.go 50.79% <100.00%> (+2.03%) ⬆️
models/unit.go 46.57% <0.00%> (-2.74%) ⬇️
modules/git/command.go 87.96% <0.00%> (-1.86%) ⬇️
routers/repo/view.go 40.66% <0.00%> (-0.59%) ⬇️
services/pull/pull.go 43.37% <0.00%> (ø)
modules/queue/workerpool.go 55.34% <0.00%> (+1.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7979c36...ffcf471. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 4, 2021
@zeripath
Copy link
Contributor Author

zeripath commented Jun 4, 2021

It would also help if it actually compiled!

zeripath added a commit to zeripath/gitea that referenced this pull request Jun 9, 2021
In go-gitea#16055 it appears that the simple 5s deadline doesn't work for large
file writes. Now we can't - or at least shouldn't just set no deadline
as go will happily let these connections block indefinitely. However,
what seems reasonable is to set some minimum rate we expect for writing.

This PR suggests the following algorithm:

* Every write has a minimum timeout of 5s (adjustable at compile time.)
* If there has been a previous write - then consider its previous
deadline, add half of the minimum timeout + 2s per kb about to written.
* If that new deadline is after the minimum timeout use that.

Fix go-gitea#16055

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added the backport/done All backports for this PR have been created label Jun 9, 2021
Copy link
Member

@6543 6543 left a comment

Choose a reason for hiding this comment

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

fix it

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 10, 2021
@6543 6543 mentioned this pull request Jun 10, 2021
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 10, 2021
@lafriks lafriks merged commit daa5a23 into go-gitea:main Jun 10, 2021
lafriks pushed a commit that referenced this pull request Jun 10, 2021
In #16055 it appears that the simple 5s deadline doesn't work for large
file writes. Now we can't - or at least shouldn't just set no deadline
as go will happily let these connections block indefinitely. However,
what seems reasonable is to set some minimum rate we expect for writing.

This PR suggests the following algorithm:

* Every write has a minimum timeout of 5s (adjustable at compile time.)
* If there has been a previous write - then consider its previous
deadline, add half of the minimum timeout + 2s per kb about to written.
* If that new deadline is after the minimum timeout use that.

Fix #16055

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: 6543 <6543@obermui.de>
@zeripath zeripath deleted the per-write-timeout-adjusting branch June 11, 2021 06:12
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 10, 2021
* Set self-adjusting deadline for connection writing

In go-gitea#16055 it appears that the simple 5s deadline doesn't work for large
file writes. Now we can't - or at least shouldn't just set no deadline
as go will happily let these connections block indefinitely. However,
what seems reasonable is to set some minimum rate we expect for writing.

This PR suggests the following algorithm:

* Every write has a minimum timeout of 5s (adjustable at compile time.)
* If there has been a previous write - then consider its previous
deadline, add half of the minimum timeout + 2s per kb about to written.
* If that new deadline is after the minimum timeout use that.

Fix go-gitea#16055

* Linearly increase timeout

* Make PerWriteTimeout, PerWritePerKbTimeouts configurable

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: 6543 <6543@obermui.de>
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected connection loss when cloning via https with slow bandwidth
6 participants