From 9b47d2ac9904bd1498715f9929623452a93e86b6 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Wed, 10 Aug 2022 00:06:48 -0500 Subject: [PATCH] Fix async context loss in WebSocketBus --- package.json | 2 +- src/support/bus/WebSocketBus.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0ed194f..7151473 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@extollo/lib", - "version": "0.13.8", + "version": "0.13.9", "description": "The framework library that lifts up your code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/support/bus/WebSocketBus.ts b/src/support/bus/WebSocketBus.ts index d70ddbc..bf133e9 100644 --- a/src/support/bus/WebSocketBus.ts +++ b/src/support/bus/WebSocketBus.ts @@ -154,8 +154,10 @@ export class WebSocketBus implements EventBus, AwareOfContainerLifecycle { }) }) - this.ws.on('close', () => this.bus.push(new WebSocketCloseEvent())) - this.ws.on('error', () => this.bus.push(new WebSocketCloseEvent())) + this.ws.on('close', () => + resource.runInAsyncScope(() => this.bus.push(new WebSocketCloseEvent()))) + this.ws.on('error', () => + resource.runInAsyncScope(() => this.bus.push(new WebSocketCloseEvent()))) await this.registerHealthCheck()