-
Notifications
You must be signed in to change notification settings - Fork 152
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
HTTP Patcher leaks response & stalls segments if no other response listener is supplied #18
Comments
Thank you for the write up. I noticed the mandatory consumption to close the subsegment if no extra listener added. Leaking memory inside the SDK is definitely a critical issue and the SDK should not force user to consume the response if no user added listener. The purposed fix looks good to me. We will spend some time testing it and add this fix to the coming release. |
Fix rolled out with 1.2.0 release. |
I know this is an old issue but I just wondered about this fix done that time to check if there is just one Looking into the NodeJs source code it seems that above check will never be true as one |
Hi @Flarna, |
The issue is for the As @Flarna has pointed out, it seems like the fix that landed was incorrect. |
If there is no response listener NodeJs core will consume (dump) the data. If there is a listener it is the user application which has to do this. Either by installing a 'data' event per hand, implicit by piping into some stream or by calling If the user application is not passing a callback this module will add one and as a result it is responsible to consume the data otherwise connections may hang. Please note that there are two ways to install a ' response' listener:
|
@omsmith @Flarna so it seems like the initially proposed fix is correct. My only question is if we are not the only listener (e.g. |
It's slightly different (and easier) here compared to the Consider user is not passing a callback and aws-xray-sdk is Monitoring Tool 1. It will add a (dumping) callback and Monitoring Tool 2 thinks users code uses a callback and therefore no need to dump the data - which is correct. If it is the other way around it works the same. |
I see! Thank you for the explanation. I will include this fix along with that in #318. |
@Flarna @omsmith I attempted this fix, however whenever I tried to check |
I did a fast try and |
Ran into this while testing the examples I was providing in #11. Not sure how much real-world impact this has, but the http patcher adds a response listener to outgoing http requests, and then sets up a listener for
res.on('end', ...)
in order to close the subsegment. The problem is, once you do add a response listener, then the response must be consumed.From the http documentation:
Currently if the developer didn't add a listener of their own, the response is never consumed, meaning the
response data is leaked, and since
end
is never fired, the subsegment will never close meaning it and its parent (sub)segment will never be flushed and sent to the daemon.Reason I'm not sure how much real-world impact this would have, is I'm not sure how often you would simply not care about the response, but I'm sure there's some sort of fire-and-forget systems out there...?
The following should fix it, but I've not developed any tests for it. It consumes the body if a callback wasn't provided, and if x-ray is the only response listener. Meaning neither of the two scenarios below occurred:
Of course, if the developer does add their own listener and neglects to consume the response, then you still run into the segment never closing, but that's a different issue, with developer error mixed in.
The text was updated successfully, but these errors were encountered: