Forráskód Böngészése

Remove wait timeout

DarthSim 7 éve
szülő
commit
f6fa71810e
3 módosított fájl, 5 hozzáadás és 19 törlés
  1. 0 6
      config.go
  2. 3 10
      server.go
  3. 2 3
      timer.go

+ 0 - 6
config.go

@@ -104,7 +104,6 @@ type config struct {
 var conf = config{
 var conf = config{
 	Bind:             ":8080",
 	Bind:             ":8080",
 	ReadTimeout:      10,
 	ReadTimeout:      10,
-	WaitTimeout:      10,
 	WriteTimeout:     10,
 	WriteTimeout:     10,
 	DownloadTimeout:  5,
 	DownloadTimeout:  5,
 	Concurrency:      runtime.NumCPU() * 2,
 	Concurrency:      runtime.NumCPU() * 2,
@@ -127,7 +126,6 @@ func init() {
 
 
 	strEnvConfig(&conf.Bind, "IMGPROXY_BIND")
 	strEnvConfig(&conf.Bind, "IMGPROXY_BIND")
 	intEnvConfig(&conf.ReadTimeout, "IMGPROXY_READ_TIMEOUT")
 	intEnvConfig(&conf.ReadTimeout, "IMGPROXY_READ_TIMEOUT")
-	intEnvConfig(&conf.WaitTimeout, "IMGPROXY_WAIT_TIMEOUT")
 	intEnvConfig(&conf.WriteTimeout, "IMGPROXY_WRITE_TIMEOUT")
 	intEnvConfig(&conf.WriteTimeout, "IMGPROXY_WRITE_TIMEOUT")
 	intEnvConfig(&conf.DownloadTimeout, "IMGPROXY_DOWNLOAD_TIMEOUT")
 	intEnvConfig(&conf.DownloadTimeout, "IMGPROXY_DOWNLOAD_TIMEOUT")
 	intEnvConfig(&conf.Concurrency, "IMGPROXY_CONCURRENCY")
 	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)
 		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 {
 	if conf.WriteTimeout <= 0 {
 		log.Fatalf("Write timeout should be greater than 0, now - %d\n", conf.WriteTimeout)
 		log.Fatalf("Write timeout should be greater than 0, now - %d\n", conf.WriteTimeout)
 	}
 	}

+ 3 - 10
server.go

@@ -144,14 +144,7 @@ func checkSecret(s string) bool {
 }
 }
 
 
 func (h *httpHandler) lock() {
 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() {
 func (h *httpHandler) unlock() {
@@ -177,8 +170,6 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 		panic(invalidSecretErr)
 		panic(invalidSecretErr)
 	}
 	}
 
 
-	t := startTimer(time.Duration(conf.WriteTimeout)*time.Second, "Processing")
-
 	h.lock()
 	h.lock()
 	defer h.unlock()
 	defer h.unlock()
 
 
@@ -188,6 +179,8 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 		return
 		return
 	}
 	}
 
 
+	t := startTimer(time.Duration(conf.WriteTimeout)*time.Second, "Processing")
+
 	imgURL, procOpt, err := parsePath(r)
 	imgURL, procOpt, err := parsePath(r)
 	if err != nil {
 	if err != nil {
 		panic(newError(404, err.Error(), "Invalid image url"))
 		panic(newError(404, err.Error(), "Invalid image url"))

+ 2 - 3
timer.go

@@ -8,11 +8,10 @@ import (
 type timer struct {
 type timer struct {
 	StartTime time.Time
 	StartTime time.Time
 	Timer     <-chan time.Time
 	Timer     <-chan time.Time
-	Info      string
 }
 }
 
 
 func startTimer(dt time.Duration, info string) *timer {
 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() {
 func (t *timer) Check() {
@@ -25,7 +24,7 @@ func (t *timer) Check() {
 }
 }
 
 
 func (t *timer) TimeoutErr() imgproxyError {
 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 {
 func (t *timer) Since() time.Duration {