From bf6c9fd46c855028b2764592f8a0e97f3eed38c4 Mon Sep 17 00:00:00 2001 From: Clinton Blackburn Date: Fri, 9 Jun 2023 10:16:32 -0700 Subject: [PATCH 1/2] Squashing worker shutdown errors If the worker is not cleanly shutdown, a log entry is created and the exception is squashed. This ensures we don't unnecessarily crash systems that are already in the process of shutting down. --- lib/temporal.explorer.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/temporal.explorer.ts b/lib/temporal.explorer.ts index 9811209..dda03ce 100644 --- a/lib/temporal.explorer.ts +++ b/lib/temporal.explorer.ts @@ -50,7 +50,12 @@ export class TemporalExplorer } onModuleDestroy() { - this.worker?.shutdown(); + try { + this.worker?.shutdown(); + } catch (err: any) { + this.logger.warn('Temporal worker was not cleanly shutdown.', { err }); + } + this.clearInterval(); } @@ -82,15 +87,14 @@ export class TemporalExplorer } as WorkerOptions; if (connectionOptions) { this.logger.verbose('Connecting to the Temporal server'); - workerOptions.connection = await NativeConnection.connect(connectionOptions); + workerOptions.connection = await NativeConnection.connect( + connectionOptions, + ); } this.logger.verbose('Creating a new Worker'); this.worker = await Worker.create( - Object.assign( - workerOptions, - workerConfig, - ), + Object.assign(workerOptions, workerConfig), ); } } From 35076bbe2aba3648623f09f2b14f80289118a0bf Mon Sep 17 00:00:00 2001 From: Clinton Blackburn Date: Wed, 21 Jun 2023 09:04:46 -0700 Subject: [PATCH 2/2] Squashing client close errors --- lib/utils/client.util.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/utils/client.util.ts b/lib/utils/client.util.ts index 731fa61..a4cd099 100644 --- a/lib/utils/client.util.ts +++ b/lib/utils/client.util.ts @@ -1,12 +1,20 @@ -import { OnApplicationShutdown } from "@nestjs/common"; -import { WorkflowClient, WorkflowClientOptions } from "@temporalio/client"; +import { OnApplicationShutdown } from '@nestjs/common'; +import { WorkflowClient, WorkflowClientOptions } from '@temporalio/client'; export function assignOnAppShutdownHook(client: WorkflowClient) { - (client as unknown as OnApplicationShutdown).onApplicationShutdown = client.connection.close; + (client as unknown as OnApplicationShutdown).onApplicationShutdown = + async () => + client.connection + ?.close() + .catch((reason) => + console.error( + `Temporal client connection was not cleanly closed: ${reason}`, + ), + ); return client; } export function getWorkflowClient(options?: WorkflowClientOptions) { const client = new WorkflowClient(options); return assignOnAppShutdownHook(client); -} \ No newline at end of file +}