From 199e6f2a386291b2fb3ea061dfc4d6dc10823267 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Wed, 7 Sep 2022 10:20:30 +0200 Subject: [PATCH] fix(core): opAsync leaks a promise on type error (#15795) --- core/01_core.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/01_core.js b/core/01_core.js index fda3e49773..e5e2c9fd5d 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -161,9 +161,14 @@ function opAsync(opName, ...args) { const promiseId = nextPromiseId++; let p = setPromise(promiseId); - const maybeError = ops[opName](promiseId, ...args); - // Handle sync error (e.g: error parsing args) - if (maybeError) return unwrapOpResult(maybeError); + try { + ops[opName](promiseId, ...args); + } catch (err) { + // Cleanup the just-created promise + getPromise(promiseId); + // Rethrow the error + throw err; + } p = PromisePrototypeThen(p, unwrapOpResult); if (opCallTracingEnabled) { // Capture a stack trace by creating a new `Error` object. We remove the