-
Notifications
You must be signed in to change notification settings - Fork 625
Mget May Cause Goroutine Leak #250
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
Comments
Hi @Bars92 Thanks for raising this issue. Since this only affects specific methods and MGET is also available as POST, I propose to change the method altogether for every API subject to this pattern. This should prevent the goroutine leak once the API has been regenerated ! |
@Anaethelion thanks for taking the time for this, your solution is even better! i'll run a few internal tests just to make sure it does prevent the goroutine leak. Any idea when will it be included in |
@Bars92 sorry for the late reply, the fix has been released with the |
Bug Description
mget request which is implemented as a GET request with body may cause go routine leaks when golang delays reading the body under golang open issue golang/go#29246. Once the issue occurs, the request will never end thus keeping the go-routine and connection stuck.
Reproduction
By using a simple program it is possible to reproduce the bug. The program will run 100 go-routines attempting to create/update a document in half of them (to generate traffic), and in the other half run MGET request on the first document:
after running for a while assuming

probeRequestBody
will take more than 200 ms we will encounter/usr/local/go/src/net/http/transfer.go:237
Using pprof you would be able to see go routines stuck waiting to read the body
That async reader fails to send EOF causing the same open issue described in this comment
How to Handle

Since this issue does not seem to resolve in golang anytime soon and this library did not have any option to workaround this behavior, we forked this library and added an option to read the
Content-Length
from the headers and copy it to the request, thus avoidingprobeRequestBody
:example in our forked repo: https://github.com/demisto/go-elasticsearch/blob/master/esapi/api.mget.go#L155 )
I would love a feedback on the issue and/or solution before pushing a PR.
The text was updated successfully, but these errors were encountered: