aboutsummaryrefslogtreecommitdiffstats
path: root/modules/ssh/ssh_graceful.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-06-10 22:25:25 +0100
committerGitHub <noreply@github.com>2021-06-11 00:25:25 +0300
commitdaa5a2354879a6dff93f431bc7e47670438995ac (patch)
treef79e9f3d2b574fa3e0cf42bb04d0ef3e8394e8b4 /modules/ssh/ssh_graceful.go
parent86e2789960439ca786c6e7a74f85f076c223d148 (diff)
downloadgitea-daa5a2354879a6dff93f431bc7e47670438995ac.tar.gz
gitea-daa5a2354879a6dff93f431bc7e47670438995ac.zip
Set self-adjusting deadline for connection writing (#16068)
* Set self-adjusting deadline for connection writing 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 * Linearly increase timeout * Make PerWriteTimeout, PerWritePerKbTimeouts configurable Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/ssh/ssh_graceful.go')
-rw-r--r--modules/ssh/ssh_graceful.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/modules/ssh/ssh_graceful.go b/modules/ssh/ssh_graceful.go
index c213aa7b88..08a7c85752 100644
--- a/modules/ssh/ssh_graceful.go
+++ b/modules/ssh/ssh_graceful.go
@@ -7,12 +7,15 @@ package ssh
import (
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
"github.com/gliderlabs/ssh"
)
func listen(server *ssh.Server) {
gracefulServer := graceful.NewServer("tcp", server.Addr, "SSH")
+ gracefulServer.PerWriteTimeout = setting.SSH.PerWriteTimeout
+ gracefulServer.PerWritePerKbTimeout = setting.SSH.PerWritePerKbTimeout
err := gracefulServer.ListenAndServe(server.Serve)
if err != nil {