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

Request with Transfer-Encoding chunked instead of Content-Length #1526

Open
olivier4576 opened this issue Aug 19, 2021 · 1 comment
Open
Assignees
Milestone

Comments

@olivier4576
Copy link

Which version of Elastic are you using?

[X] elastic.v7 (for Elasticsearch 7.x)
[ ] elastic.v6 (for Elasticsearch 6.x)
[ ] elastic.v5 (for Elasticsearch 5.x)
[ ] elastic.v3 (for Elasticsearch 2.x)
[ ] elastic.v2 (for Elasticsearch 1.x)

Please describe the expected behavior

ELK search sends an HTTP request with a "Content-Length: nnn" header.

Please describe the actual behavior

ELK search sends an HTTP request with a "Transfer-Encoding: chunked" header.
Transfer-Encoding chunked can be used in a HTTP request but is rarely used and this can cause problems to other tools.

Any steps to reproduce the behavior?

Reproduced in any search request.

The problem is in request.go, in func setBodyHeader(). When called in setBodyJson() or setBodyGzip(), the body is a bytes.Reader, then it must be converted to a bytes.Reader and not a bytes.Buffer to get the ContentLength.

@olivere
Copy link
Owner

olivere commented Jan 7, 2022

I've did a few tests, especially with the PR #1441, and the benchmarks are alarming:

$ go test -test.bench=RequestSetBody -run=NONE > old.txt
...
$ go test -test.bench=RequestSetBody -run=NONE > new.txt
...
$ benchcmp old.txt new.txt
benchcmp is deprecated in favor of benchstat: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
benchmark                                              old ns/op      new ns/op      delta
BenchmarkSearchMatchAll-8                              1979627        1041992666     +52535.81%

benchmark                                              old allocs     new allocs     delta
BenchmarkSearchMatchAll-8                              173            4881           +2721.39%

benchmark                                              old bytes      new bytes      delta
BenchmarkSearchMatchAll-8                              96174          1823568        +1796.11%

We have to be very cautious. I'll have another go at this in a later release.

@olivere olivere self-assigned this Jan 7, 2022
olivere added a commit that referenced this issue Jan 7, 2022
This commit experiments with different encodings for the HTTP request
body.

See #1526
See #1441 (PR)
@olivere olivere modified the milestones: 7.0.32, 7.0.33 Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants