fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

Context is canceled on a newly initialized fasthttp.RequestCtx in 1.56.0

Open oschwald opened this issue 1 year ago • 2 comments

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.

oschwald avatar Oct 04 '24 21:10 oschwald

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

dza89 avatar Oct 09 '24 07:10 dza89

我遇到了同样的问题。恢复到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 done

unfamiliar 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.

byte0o avatar Oct 09 '24 08:10 byte0o

Should be fixed in https://github.com/valyala/fasthttp/pull/1890, I'll publish a release tomorrow.

erikdubbelboer avatar Oct 27 '24 19:10 erikdubbelboer

Thank you!

oschwald avatar Oct 27 '24 19:10 oschwald

Graat work, thanks a lot!

dza89 avatar Oct 28 '24 03:10 dza89