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

Wrong path on valid requests when error handler exists #548

Closed
avivpxi opened this issue Feb 26, 2019 · 2 comments
Closed

Wrong path on valid requests when error handler exists #548

avivpxi opened this issue Feb 26, 2019 · 2 comments
Assignees
Labels

Comments

@avivpxi
Copy link
Contributor

avivpxi commented Feb 26, 2019

When i register an error handler to a server instance, whenever i peeks into ctx.Path() method, it seem to corrupt the value of another request which gets handled later on.
I'm building my server with github.com/valyala/fasthttp v1.2.0,
and able to reproduce the issue using this hello world example:

package main

import (
	"fmt"
	"github.com/valyala/fasthttp"
)

func main() {
	server := &fasthttp.Server{
		Handler: requestHandler,
		ErrorHandler: errorHandler,
		MaxRequestBodySize: 10,
		Concurrency: 1,
	}
	if err := server.ListenAndServe(":8080"); err != nil {
		fmt.Println(err)
	}
}

func requestHandler(ctx *fasthttp.RequestCtx) {
	fmt.Printf("handler requested resource: %v %v\n", string(ctx.Method()), string(ctx.Path()))
	fmt.Fprintf(ctx, "Hello, world\n")
}

func errorHandler(ctx *fasthttp.RequestCtx, err error) {
	fmt.Printf("error requested resource: %v %v\n", string(ctx.Method()), string(ctx.Path()))
	fmt.Println("error handler", err)
}

Note that i use MaxRequestBodySize to be able to trigger the error handler using the sent body size, and also note the concurrency parameter (which causes the issue to appear faster).

Now these are the steps to reproduce the issue:

curl -XPOST http://localhost:8080/a -d 'valid body' -> handler requested resource: POST /a
curl -XPOST http://localhost:8080/b -d 'invalid body' -> error requested resource: POST /b
curl -XPOST http://localhost:8080/c -d 'invalid body' -> error requested resource: POST /c
curl -XPOST http://localhost:8080/d -d 'valid body' -> handler requested resource: POST /c

Note that this result is non-deterministic, the last request can also result in handler requested resource: POST /b, but the value was inaccurate every time i tried these steps.

@kirillDanshin kirillDanshin self-assigned this Mar 2, 2019
@kirillDanshin
Copy link
Collaborator

@avivpxi thanks for pointing out. #551 fixes this issue

@lxj15398019970
Copy link

i think this bug is still exist in v 1.50

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

No branches or pull requests

3 participants