Context is canceled on a newly initialized fasthttp.RequestCtx in 1.56.0
Given the following code, a "context canceled" error is printed out in 1.56.0 but not 1.55.0.
package main
import (
"fmt"
"github.com/valyala/fasthttp"
)
func main() {
var r fasthttp.Request
r.Header.SetMethod("GET")
r.SetRequestURI("http://example/")
var requestCtx fasthttp.RequestCtx
requestCtx.Init(&r, nil, nil)
fmt.Println(requestCtx.Err())
}
I was able to bisect this to a7d488a9.
We use code similar to this in our tests to create a fasthttp.RequestCtx to pass to the handler. This code has been working unchanged for many years.
I am seeing the same issue. Reverting to 1.55 solves the issue.
done <- struct{}{}
This line signals the task is done, resulting in a cancelled context
Fix:
done := ctx.s.done
if done == nil {
done = make(chan struct{})
}
return done
unfamiliar with the original issue though.
@erikdubbelboer @byte0o
我遇到了同样的问题。恢复到1.55即可解决问题。
done <- struct{}{}此行表示任务已完成,导致上下文被取消
使固定:
done := ctx.s.done if done == nil { done = make(chan struct{}) } return done尽管不熟悉原始问题。
@erikdubbelboer @byte0o
I am seeing the same issue. Reverting to 1.55 solves the issue.
done <- struct{}{}This line signals the task is done, resulting in a cancelled context
Fix:
done := ctx.s.done if done == nil { done = make(chan struct{}) } return doneunfamiliar with the original issue though.
@erikdubbelboer @byte0o
@dza89 This change is to address the https://github.com/valyala/fasthttp/pull/1662 issue,Now the semantics of the Err function need to be reconsidered.
Should be fixed in https://github.com/valyala/fasthttp/pull/1890, I'll publish a release tomorrow.
Thank you!
Graat work, thanks a lot!