From d2dd7d16946ac1f4bea600be245f278a5eb23b8c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 28 Sep 2012 09:13:17 -0700 Subject: [PATCH] add 30 seconds http read timeout --- weed-fs/src/cmd/weed/master.go | 8 +++++++- weed-fs/src/cmd/weed/volume.go | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.go index bdeb2e78d..7e0e0ec87 100644 --- a/weed-fs/src/cmd/weed/master.go +++ b/weed-fs/src/cmd/weed/master.go @@ -10,6 +10,7 @@ import ( "pkg/topology" "strconv" "strings" + "time" ) func init() { @@ -140,7 +141,12 @@ func runMaster(cmd *Command, args []string) bool { topo.StartRefreshWritableVolumes() log.Println("Start Weed Master", VERSION, "at port", strconv.Itoa(*mport)) - e := http.ListenAndServe(":"+strconv.Itoa(*mport), nil) + srv := &http.Server{ + Addr:":"+strconv.Itoa(*mport), + Handler: http.DefaultServeMux, + ReadTimeout: 30*time.Second, + } + e := srv.ListenAndServe() if e != nil { log.Fatalf("Fail to start:%s", e.Error()) } diff --git a/weed-fs/src/cmd/weed/volume.go b/weed-fs/src/cmd/weed/volume.go index cb052a4be..4df873bec 100644 --- a/weed-fs/src/cmd/weed/volume.go +++ b/weed-fs/src/cmd/weed/volume.go @@ -272,8 +272,13 @@ func runVolume(cmd *Command, args []string) bool { }() log.Println("store joined at", *masterNode) - log.Println("Start Weed volume server", VERSION, "at http://" + *ip + ":" + strconv.Itoa(*vport)) - e := http.ListenAndServe(":"+strconv.Itoa(*vport), nil) + log.Println("Start Weed volume server", VERSION, "at http://"+*ip+":"+strconv.Itoa(*vport)) + srv := &http.Server{ + Addr:":"+strconv.Itoa(*vport), + Handler: http.DefaultServeMux, + ReadTimeout: 30*time.Second, + } + e := srv.ListenAndServe() if e != nil { log.Fatalf("Fail to start:%s", e.Error()) }