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

fix: reset request after reset user values on keep-alive connections #1162

Merged
merged 2 commits into from Nov 23, 2021
Merged

fix: reset request after reset user values on keep-alive connections #1162

merged 2 commits into from Nov 23, 2021

Conversation

savsgio
Copy link
Contributor

@savsgio savsgio commented Nov 17, 2021

This fix the use cases that reference a RequestCtx into user values that implements io.Closer

Example:

func handler(ctx *fasthttp.RequestCtx) {
	rd := acquireRequestDuration()
	rd.ctx = ctx
	rd.start = time.Now()

	ctx.SetUserValue("__http::requestDuration__", rd)
}

func (rd *requestDuration) Close() error {
	duration := time.Since(rd.start)
	statusCode := strconv.Itoa(rd.ctx.Response.StatusCode())  // ISSUE: INVALID VALUE, ALWAYS IS 200
	method := string(rd.ctx.Request.Header.Method())  // ISSUE: INVALID VALUE
	path := string(rd.ctx.Request.URI().Path())  // ISSUE: INVALID VALUE

	requestsDurationHistogramVec.WithLabelValues(
		statusCode, method, path,
	).Observe(duration.Seconds())

	releaseRequestDuration(rd)

	return nil
}

@savsgio
Copy link
Contributor Author

savsgio commented Nov 17, 2021

The test in go 1.15 fails because timeout. Could you run it again, please!

@erikdubbelboer
Copy link
Collaborator

erikdubbelboer commented Nov 18, 2021

I'm not sure I understand what this is for. Can you maybe add a test case that fails before your change and passes afterwards?

@erikdubbelboer erikdubbelboer merged commit 017f0aa into valyala:master Nov 23, 2021
11 checks passed
@erikdubbelboer
Copy link
Collaborator

erikdubbelboer commented Nov 23, 2021

Thanks, good fix!

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

Successfully merging this pull request may close these issues.

None yet

2 participants