Skip to content

Commit

Permalink
fix(span): Do not pass stack frames into promises
Browse files Browse the repository at this point in the history
Passing error stack frames into a promise context makes it
uncollectable by the garbage collector.
  • Loading branch information
Stephen Belanger committed Mar 15, 2018
1 parent 9ce6460 commit 7251dfa
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/instrumentation/index.js
Expand Up @@ -32,11 +32,9 @@ Instrumentation.prototype.start = function () {
maxQueueSize: this._agent._conf.maxQueueSize
}
this._queue = new Queue(qopts, function onFlush (transactions, done) {
Promise.all(transactions).then(function (transactions) {
if (self._agent._conf.active && transactions.length > 0) {
request.transactions(self._agent, transactions, done)
}
}, done)
if (self._agent._conf.active && transactions.length > 0) {
request.transactions(self._agent, transactions, done)
}
})

if (this._agent._conf.asyncHooks && semver.gte(process.version, '8.2.0')) {
Expand Down Expand Up @@ -72,16 +70,13 @@ Instrumentation.prototype.addEndedTransaction = function (transaction) {
debug('adding transaction to queue %o', {id: transaction.id})
// encode the transaction as early as possible in an attempt to free up
// objects for garbage collection
queue.add(new Promise(function (resolve, reject) {
transaction._encode(function (err, payload) {
// As of writing this comment, _encode swallows all errors. So the
// following error handling logic shouldn't actually be needed
if (err) reject(err)
else resolve(payload)
})
}).catch(function (err) {
logger.error('error encoding transaction %s: %s', transaction.id, err.message)
}))
transaction._encode(function (err, payload) {
if (err) {
logger.error('error encoding transaction %s: %s', transaction.id, err.message)
return
}
queue.add(payload)
})
} else {
debug('ignoring transaction %o', {id: transaction.id})
}
Expand Down

0 comments on commit 7251dfa

Please sign in to comment.