mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
Remove wait timeout
This commit is contained in:
parent
9ba634fc35
commit
f6fa71810e
@ -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)
|
||||
}
|
||||
|
13
server.go
13
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"))
|
||||
|
5
timer.go
5
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user