From 156e2ab54013b38bb3d13f98a4ee41d0cd438561 Mon Sep 17 00:00:00 2001 From: mappu Date: Wed, 17 May 2023 18:18:02 +1200 Subject: [PATCH] thumbnail: if the request is cancelled, don't wait for the semaphore --- thumb.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/thumb.go b/thumb.go index b1bd24c..a6d0beb 100644 --- a/thumb.go +++ b/thumb.go @@ -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 {