From 95b0e3dba1a9f986cfc4af4b90598299e9709a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Thu, 25 Jul 2024 14:20:25 +0200 Subject: [PATCH 1/2] chore(utils/httpbin): explicitly return status code 200 on context cancellation in /delay endpoint --- utils/httpbin/httpbin.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/httpbin/httpbin.go b/utils/httpbin/httpbin.go index af3bf730..482be0b9 100644 --- a/utils/httpbin/httpbin.go +++ b/utils/httpbin/httpbin.go @@ -69,8 +69,9 @@ func delayHandler(w http.ResponseWriter, r *http.Request) { case <-r.Context().Done(): t.Stop() case <-t.C: - w.WriteHeader(http.StatusOK) } + + w.WriteHeader(http.StatusOK) } // statusHandler implements the /status/{code} endpoint. From c1f62fdefb366e6b356e71496a2c3f2561a1b2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Fri, 26 Jul 2024 10:02:31 +0200 Subject: [PATCH 2/2] chore(utils/httpbin): ensure timer is always stopped in /delay endpoint --- utils/httpbin/httpbin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/httpbin/httpbin.go b/utils/httpbin/httpbin.go index 482be0b9..07532c6e 100644 --- a/utils/httpbin/httpbin.go +++ b/utils/httpbin/httpbin.go @@ -65,6 +65,8 @@ func delayHandler(w http.ResponseWriter, r *http.Request) { } t := time.NewTimer(time.Duration(ms) * time.Millisecond) + defer t.Stop() + select { case <-r.Context().Done(): t.Stop()