Skip to content

Commit

Permalink
fix RequestCtx is canceled (#1879) (#1890)
Browse files Browse the repository at this point in the history
Create done channel in fakeServer during the initialization of newRequestCtx to prevent the done channel from being nil
  • Loading branch information
ksw2000 authored Oct 27, 2024
1 parent 40bdc4a commit 803c25e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
10 changes: 10 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 803c25e

Please sign in to comment.