diff --git a/lib/cwmp.ts b/lib/cwmp.ts index 0e9584b..b28e046 100644 --- a/lib/cwmp.ts +++ b/lib/cwmp.ts @@ -1211,12 +1211,17 @@ export function listener( }) .catch((err) => { currentSessions.delete(httpResponse.connection); - httpResponse.writeHead(500, { Connection: "close" }); - httpResponse.end(`${err.name}: ${err.message}`); stats.concurrentRequests -= 1; setTimeout(() => { throw err; }); + try { + httpResponse.connection.unref(); + httpResponse.writeHead(500, { Connection: "close" }); + httpResponse.end(`${err.name}: ${err.message}`); + } catch (err) { + // Ignore + } }); } diff --git a/lib/ui.ts b/lib/ui.ts index 759454c..0e2192c 100644 --- a/lib/ui.ts +++ b/lib/ui.ts @@ -60,7 +60,9 @@ const getAuthorizer = memoize( ); koa.on("error", async (err) => { - throw err; + setTimeout(() => { + throw err; + }); }); koa.use(async (ctx, next) => {