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: fixes EOF error when having HTTP POST requests #342

Merged

Conversation

jrauschenbusch
Copy link
Contributor

Mittens requests are recycled within the requests channel. Once the body i/o reader was closed, succeeding requests were not successful.

📝 Description

Currently mittens is broken due to an bug introduced in v1.46. During the processing of requests an i/o reader is passed to the client which leads to EOF errors on server side when the same request body is read the 2nd time. Hence only the first request of a warm-up succeeds and all others fail. This should only affect configurations using POST data, but this needs to be fixed.

🔗 Related Issues

mittens requests are recycled within the requests channel. Once the body i/o reader was closed, succeeding requests were not succesful.
@jrauschenbusch jrauschenbusch requested a review from a team as a code owner January 17, 2024 10:19
const respType = "http"

var body io.Reader
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re-introducing the i/o reader per request

if err != nil {
log.Printf("Failed to create request: %s %s: %v", method, url, err)
return response.Response{Duration: time.Duration(0), Err: err, Type: respType}
}

if req.Body != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Body must be closed when there is no error and when a body is present. In case of GET there is no Body.

}, nil
}

func compressGzip(data []byte) io.Reader {
pr, pw := io.Pipe()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Optimization not required as mittens requests are re-used in the channel. So compression is only done once for each request element.

@@ -188,6 +191,36 @@ func TestGrpcAndHttp(t *testing.T) {
assert.True(t, readyFileExists)
}

func TestCompressWithGZip(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

e2e test for compression support

@jrauschenbusch
Copy link
Contributor Author

@nikos912000 Sorry for having to fix this directly after the release of v1.46. Unfortunately all existing tests were not able to detect an issue within the request processing. I tried to add a useful test here, but maybe there should be another one.

@jrauschenbusch
Copy link
Contributor Author

@nikos912000 @worldtiki Review required

pw.CloseWithError(err)
}()
return pr
func compressGzip(data []byte) (io.Reader, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aligned implementation of all compression functions

Copy link
Member

@nikos912000 nikos912000 left a comment

Choose a reason for hiding this comment

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

Thanks for this.
Something looks wrong with the flags in the tests, these are no more passed - I don't think it was this PR that caused it.
A bit busy to debug properly atm but I will try find some time and let our teams know.

@nikos912000
Copy link
Member

I debugged this and recalled that we identified this issue in the past. It has to do with the fact that the command line arguments are parsed after setting their default values.

For instance, the HTTPPort will be 8080 at this point and the ReadinessPort will be set to its default value, which is 8080 here, too.
Finally, the cmd args will be parsed at this point setting only the HTTPPort to the passed value.

As this does not have to do with this PR, happy to merge it.

@jrauschenbusch
Copy link
Contributor Author

I tested it now in our pre-production and afterwards production. Works like a charm. HTTP/2 and stream compression.

@nikos912000 nikos912000 self-requested a review February 3, 2024 09:48
@nikos912000 nikos912000 merged commit 8221e46 into ExpediaGroup:main Feb 3, 2024
3 checks passed
@sumitanvekar
Copy link
Contributor

@jrauschenbusch thank you for contribution. this is now released in https://github.com/ExpediaGroup/mittens/releases/tag/1.47.0

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

Successfully merging this pull request may close these issues.

4 participants