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

proxy: fix proxy panic caused by broken backend #2984

Closed
wants to merge 2 commits into from

Conversation

AlexanderYastrebov
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov commented Mar 14, 2024

Broken backend that closes connection before sending response body may trigger proxy panic if client sends Expect: 100-continue header, see golang/go#53808

Close outgoing request body to fix proxy panic.

@AlexanderYastrebov AlexanderYastrebov added the bugfix Bug fixes and patches label Mar 14, 2024
@AlexanderYastrebov AlexanderYastrebov marked this pull request as ready for review March 14, 2024 13:01
@@ -192,9 +192,9 @@ func (c *context) shunted() bool {
return c.servedWithResponse
}

func (c *context) setResponse(r *http.Response, preserveOriginal bool) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to cleanup this although its unrelated

Comment on lines -1543 to -1550
defer func() {
if ctx.response != nil && ctx.response.Body != nil {
err := ctx.response.Body.Close()
if err != nil {
ctx.Logger().Errorf("error during closing the response body: %v", err)
}
}
}()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided not to pile-up defers but to use straightforward cleanup sequence after streaming the response.
Would like to refactor other defers as well separately.

// based on the augmented incoming request
func (p *Proxy) mapRequest(ctx *context, requestContext stdlibcontext.Context) (*http.Request, routing.Metrics, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to createOutgoingRequest?

@AlexanderYastrebov AlexanderYastrebov marked this pull request as draft March 14, 2024 13:23
@AlexanderYastrebov AlexanderYastrebov force-pushed the proxy/fix-go53808 branch 2 times, most recently from 65b2792 to 13dac9e Compare March 22, 2024 14:34
Broken backend that closes connection before sending response body
may trigger proxy panic if client sends `Expect: 100-continue` header,
see golang/go#53808

Signed-off-by: Alexander Yastrebov <[email protected]>
Close outgoing request body to fix proxy panic.

Signed-off-by: Alexander Yastrebov <[email protected]>
@AlexanderYastrebov
Copy link
Member Author

The plan is to fix the stdlib, see golang/go#66594

@AlexanderYastrebov AlexanderYastrebov deleted the proxy/fix-go53808 branch April 4, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Bug fixes and patches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant