This repository was archived by the owner on Oct 23, 2023. It is now read-only.
Fix autoBreadcrumb http instrumentation memory leak #296
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #276/version 1.1.3 introduced a memory leak in our http instrumentation as reported in #295. The core issue was that we were monkeypatching
http.ClientRequest.prototype.emit
during everyClientRequest
instantiation, instead of just during initial instrumentation, which meant that for each outbound http request made, we kept a bunch of stuff around in a closure.Users on raven-node 1.1.3 or 1.1.4 with long-running processes that made outbound http requests found their memory usage growing steadily over time.
This PR refactors the
ClientRequest
instrumentation to only monkeypatchhttp.ClientRequest.prototype.emit
once during initial Raven setup when we also monkeypatch the constructor. The monkeypatchedemit
method previously found the request url by closure reference, but now the constructor attaches a__ravenBreadcrumbUrl
property to the request object andemit
grabs that instead.I confirmed the issue and fix using memwatch-next (plus express, some outbound requesting, and some apachebenching) and have ideas for how to use that to automate some "did we intro a memory leak" sanity testing, but that can come later. That effort will have to test multiple different possible causes; the manual memory load test in https://github.com/getsentry/raven-node/blob/master/test/manual/context-memory.js would not have caught this because it only exercises contexts, not each of the different autoBreadcrumb instrumentation options.
This should fix #295. As soon as this merges I'll publish a new version.
/cc @benvinegar @MaxBittker @maxcountryman