From f6fa71810ef8a5d9961c6cb3a3be79ccc9cf3807 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Mon, 19 Mar 2018 14:58:52 +0600 Subject: [PATCH] Remove wait timeout --- config.go | 6 ------ server.go | 13 +++---------- timer.go | 5 ++--- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/config.go b/config.go index 4d296ca0..be0af0da 100644 --- a/config.go +++ b/config.go @@ -104,7 +104,6 @@ type config struct { var conf = config{ Bind: ":8080", ReadTimeout: 10, - WaitTimeout: 10, WriteTimeout: 10, DownloadTimeout: 5, Concurrency: runtime.NumCPU() * 2, @@ -127,7 +126,6 @@ func init() { strEnvConfig(&conf.Bind, "IMGPROXY_BIND") intEnvConfig(&conf.ReadTimeout, "IMGPROXY_READ_TIMEOUT") - intEnvConfig(&conf.WaitTimeout, "IMGPROXY_WAIT_TIMEOUT") intEnvConfig(&conf.WriteTimeout, "IMGPROXY_WRITE_TIMEOUT") intEnvConfig(&conf.DownloadTimeout, "IMGPROXY_DOWNLOAD_TIMEOUT") intEnvConfig(&conf.Concurrency, "IMGPROXY_CONCURRENCY") @@ -168,10 +166,6 @@ func init() { log.Fatalf("Read timeout should be greater than 0, now - %d\n", conf.ReadTimeout) } - if conf.WaitTimeout <= 0 { - log.Fatalf("Wait timeout should be greater than 0, now - %d\n", conf.WaitTimeout) - } - if conf.WriteTimeout <= 0 { log.Fatalf("Write timeout should be greater than 0, now - %d\n", conf.WriteTimeout) } diff --git a/server.go b/server.go index bb782eab..c8aadf7f 100644 --- a/server.go +++ b/server.go @@ -144,14 +144,7 @@ func checkSecret(s string) bool { } func (h *httpHandler) lock() { - t := startTimer(time.Duration(conf.WaitTimeout)*time.Second, "Waiting") - - select { - case h.sem <- struct{}{}: - // Go ahead - case <-t.Timer: - panic(t.TimeoutErr()) - } + h.sem <- struct{}{} } func (h *httpHandler) unlock() { @@ -177,8 +170,6 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { panic(invalidSecretErr) } - t := startTimer(time.Duration(conf.WriteTimeout)*time.Second, "Processing") - h.lock() defer h.unlock() @@ -188,6 +179,8 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { return } + t := startTimer(time.Duration(conf.WriteTimeout)*time.Second, "Processing") + imgURL, procOpt, err := parsePath(r) if err != nil { panic(newError(404, err.Error(), "Invalid image url")) diff --git a/timer.go b/timer.go index 0b133e28..38803d06 100644 --- a/timer.go +++ b/timer.go @@ -8,11 +8,10 @@ import ( type timer struct { StartTime time.Time Timer <-chan time.Time - Info string } func startTimer(dt time.Duration, info string) *timer { - return &timer{time.Now(), time.After(dt), info} + return &timer{time.Now(), time.After(dt)} } func (t *timer) Check() { @@ -25,7 +24,7 @@ func (t *timer) Check() { } func (t *timer) TimeoutErr() imgproxyError { - return newError(503, fmt.Sprintf("Timeout after %v (%s)", t.Since(), t.Info), "Timeout") + return newError(503, fmt.Sprintf("Timeout after %v", t.Since()), "Timeout") } func (t *timer) Since() time.Duration {