Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
oschwald opened this issue Oct 4, 2024 · 5 comments
Closed

Comments

@oschwald
Copy link

oschwald commented Oct 4, 2024

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

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.

@dza89
Copy link

dza89 commented Oct 9, 2024

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

@byte0o
Copy link
Contributor

byte0o commented Oct 9, 2024

我遇到了同样的问题。恢复到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 #1662 issue,Now the semantics of the Err function need to be reconsidered.

ksw2000 added a commit to ksw2000/fasthttp that referenced this issue Oct 26, 2024
Create done channel in fakeServer during the initialization of newRequestCtx to prevent the done channel from being nil
erikdubbelboer pushed a commit that referenced this issue Oct 27, 2024
Create done channel in fakeServer during the initialization of newRequestCtx to prevent the done channel from being nil
@erikdubbelboer
Copy link
Collaborator

Should be fixed in #1890, I'll publish a release tomorrow.

@oschwald
Copy link
Author

Thank you!

@dza89
Copy link

dza89 commented Oct 28, 2024

Graat work, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants