thumbnail: if the request is cancelled, don't wait for the semaphore

This commit is contained in:
mappu 2023-05-17 18:18:02 +12:00
parent ad56309cb0
commit 156e2ab540
1 changed files with 6 additions and 1 deletions

View File

@ -62,7 +62,12 @@ func (this *Server) handleThumb(w http.ResponseWriter, r *http.Request, thumbnai
}
// Only a limited number of thumbnails can be generated concurrently
<-this.thumbnailSem
select {
case <-this.thumbnailSem:
case <-r.Context().Done():
http.Error(w, r.Context().Err().Error(), 400) // probably won't be delivered anyway
return
}
defer func() { this.thumbnailSem <- struct{}{} }()
if ctx.Err() != nil {