From a111cc48edaebe55419396ffaedcd0fd819ccae9 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Wed, 13 Sep 2023 16:05:53 -0400 Subject: [PATCH] fix #3318: ignore invalid commands for old builds --- lib/shared/common.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/shared/common.ts b/lib/shared/common.ts index 608f79ff416..d57ec310f0e 100644 --- a/lib/shared/common.ts +++ b/lib/shared/common.ts @@ -592,12 +592,17 @@ export function createChannel(streamIn: StreamIn): StreamOut { if (typeof request.key === 'number') { const requestCallbacks = requestCallbacksByKey[request.key] - if (requestCallbacks) { - const callback = requestCallbacks[request.command] - if (callback) { - await callback(id, request) - return - } + if (!requestCallbacks) { + // Ignore invalid commands for old builds that no longer exist. + // This can happen when "context.cancel" and "context.dispose" + // is called while esbuild is processing many files in parallel. + // See https://github.com/evanw/esbuild/issues/3318 for details. + return + } + const callback = requestCallbacks[request.command] + if (callback) { + await callback(id, request) + return } }