From e468893748df81aa93b20ad4af8dc2ac4666663a Mon Sep 17 00:00:00 2001 From: laizhenkun Date: Thu, 12 Dec 2013 17:15:08 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug:=20a=20broken=20http=20connection=20w?= =?UTF-8?q?ill=20cause=20io.Copy()=20stuck=20and=20file=E2=80=99s=20offset?= =?UTF-8?q?=20will=20not=20be=20updated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cmd/tusd/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cmd/tusd/main.go b/src/cmd/tusd/main.go index c12348a..61182c3 100644 --- a/src/cmd/tusd/main.go +++ b/src/cmd/tusd/main.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strconv" + "time" ) const basePath = "/files/" @@ -73,8 +74,18 @@ func main() { go handleUploads(tusHandler) + // On http package's default action, a broken http connection will cause io.Copy() stuck because it always suppose more data will coming and wait for them infinitely + // To prevent it happen, we should set a specific timeout value on http server + s := &http.Server{ + Addr: addr, + Handler: nil, + ReadTimeout: 8 * time.Second, + WriteTimeout: 8 * time.Second, + MaxHeaderBytes: 0, + } + log.Printf("servering clients at http://localhost%s", addr) - if err := http.ListenAndServe(addr, nil); err != nil { + if err := s.ListenAndServe(); err != nil { panic(err) } }