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

Middleware Replay Events Not Triggering Correctly with Rate Limiting in Gor #1253

Open
ohs30359-nobuhara opened this issue Jun 27, 2024 · 0 comments
Labels
bug Something isn't working question Question about GoReplay and how to use it

Comments

@ohs30359-nobuhara
Copy link

Issue Description:
I am currently using a simple server and middleware for testing with Gor. The server code is as follows:

func handler(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
    body := r.URL.RawQuery
    fmt.Println(body)
    w.Write([]byte(body))
}

func main() {
    http.HandleFunc("/", handler)

    port := "8080"
    if len(os.Args) > 1 {
        port = os.Args[1]
    }
    if err := http.ListenAndServe(":"+port, nil); err != nil {
        panic(err)
    }
}

The middleware is based on a sample from the Gor documentation:

gor.on("request", function(req) {
    gor.on("response", req.ID, function(resp) {
        gor.on("replay", req.ID, function(repl) {
            console.error("replay", req.ID)
            return repl;
        })
        return resp;
    })
    return req;
})

I run Gor with the following command:

sudo gor --input-raw :3000 --output-http "http://localhost:8000|10%" --middleware ./middleware/test.js --output-http-track-response --input-raw-track-response --http-allow-method GET --input-raw-buffer-size 1048576 --input-raw-override-snaplen

When I send 100 requests per second using Apache Bench:

ab -n 100 -c 100 "http://localhost:3000/?sample=aaa"

I can confirm that the target server receives exactly 10 requests, as expected due to the 10% rate limit:

sample=aaaaaa
sample=aaaaaa
sample=aaaaaa
sample=aaaaaa
sample=aaaaaa
sample=aaaaaa
sample=aaaaaa
sample=aaaaaa
sample=aaaaaa
sample=aaaaaa

However, in the middleware, only 2 replay events are triggered:

replay f0e40bb87f000001fd11521f
replay f0ea0bb87f0000014d46b09c

This issue does not occur if I remove the 10% rate limit.

Question:

Could you help me understand why only 2 replay events are being triggered in the middleware when the rate limit is applied? How can this be resolved to ensure all replay events are triggered correctly?

@dosubot dosubot bot added bug Something isn't working question Question about GoReplay and how to use it labels Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Question about GoReplay and how to use it
Projects
None yet
Development

No branches or pull requests

1 participant