From 803c25e54ced13c8a688ce858104e4e4a6b3148c Mon Sep 17 00:00:00 2001 From: Kashiwa <13825170+ksw2000@users.noreply.github.com> Date: Mon, 28 Oct 2024 03:15:57 +0800 Subject: [PATCH] fix RequestCtx is canceled (#1879) (#1890) Create done channel in fakeServer during the initialization of newRequestCtx to prevent the done channel from being nil --- server.go | 1 + server_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/server.go b/server.go index 8cd6fef..bcf30cb 100644 --- a/server.go +++ b/server.go @@ -2789,6 +2789,7 @@ func (ctx *RequestCtx) Value(key any) any { } var fakeServer = &Server{ + done: make(chan struct{}), // Initialize concurrencyCh for TimeoutHandler concurrencyCh: make(chan struct{}, DefaultConcurrency), } diff --git a/server_test.go b/server_test.go index 75ea137..59f27d1 100644 --- a/server_test.go +++ b/server_test.go @@ -4414,3 +4414,13 @@ func TestRequestBodyStreamReadIssue1816(t *testing.T) { t.Fatal(err) } } + +func TestRequestCtxInitShouldNotBeCanceledIssue1879(t *testing.T) { + var r Request + var requestCtx RequestCtx + requestCtx.Init(&r, nil, nil) + err := requestCtx.Err() + if err != nil { + t.Fatal(err) + } +}