olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch
https://olivere.github.io/elastic/
MIT License
7.39k stars 1.15k forks source link

`Client::PerformRequest` dumps response before checking for `MaxResponseSize` #1647

Open hazimavdal opened 1 year ago

hazimavdal commented 1 year ago

Which version of Elastic are you using?

[ ] elastic.v7 (for Elasticsearch 7.x)

Please describe the expected behavior

Client::dumpResponse should check for MaxResponseSize before dumping the request similar to what Client::newResponse does. Currently the library can cause subtle OOM situations even if the request is bounded by a MaxResponseSize limit unless the trace logger is also nil.

Consumers should be able to set a trace logger without risking OOMs. At the very least it should be made clear in the documentation that MaxResponseSize must be set and the trace logger must be nil to guard against OOM exceptions.

Please describe the actual behavior

Library can cause OOM exceptions if trace logger is set, regardless of the MaxResponseSize limits.

Any steps to reproduce the behavior?

Instantiate a client and set both the MaxResponseSize and the trace logger to be non-zero valued. You will see that the process will use a lot of memory even if you set the MaxResponseSize to be a low value.