Skip to content

Commit

Permalink
Remove memory leak from guaranteed unresolved/unrejected Promise.
Browse files Browse the repository at this point in the history
I question whether or not we want to actually guarantee async execution of
this method and not give the opportunity to the user to actually make it
block if they'd like to, but we certainly should ensure that Promises should
not be created on every request and never resolve or reject, which seems
like a prime avenue for a DoS via memory leak.

Of course, these should be garbage collected eventually, but we can avoid
creating them that way.
  • Loading branch information
abernix committed Nov 15, 2019
1 parent 7e84c64 commit 77021d2
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ for observability purposes, but all operations will be permitted.`,
requestContext.metrics.registeredOperation = true;
return;
} else {
if (options.onUnregisteredOperation) {
new Promise(() => {
if (options.onUnregisteredOperation) {
options.onUnregisteredOperation(requestContext);
}
// If defined, this method should not block, whether async or not.
if (typeof options.onUnregisteredOperation === 'function') {
const onUnregisteredOperation = options.onUnregisteredOperation;
Promise.resolve().then(() => {
onUnregisteredOperation(requestContext);
});
}
}
Expand Down Expand Up @@ -234,11 +234,11 @@ for observability purposes, but all operations will be permitted.`,
}

if (shouldForbidOperation) {
if (options.onForbiddenOperation) {
new Promise(() => {
if (options.onForbiddenOperation) {
options.onForbiddenOperation(requestContext);
}
// If defined, this method should not block, whether async or not.
if (typeof options.onForbiddenOperation === 'function') {
const onForbiddenOperation = options.onForbiddenOperation;
Promise.resolve().then(() => {
onForbiddenOperation(requestContext);
});
}
if (!options.dryRun) {
Expand Down

0 comments on commit 77021d2

Please sign in to comment.