diff --git a/src/plugin/v2/grpc_plugin.ts b/src/plugin/v2/grpc_plugin.ts index 9ba10da..97f2ab5 100644 --- a/src/plugin/v2/grpc_plugin.ts +++ b/src/plugin/v2/grpc_plugin.ts @@ -100,7 +100,9 @@ class PluginGRPCServer { } async render(call: grpc.ServerUnaryCall, callback: grpc.sendUnaryData) { - const { signal } = new AbortController(); + const abortController = new AbortController(); + const { signal } = abortController; + const req = call.request; const headers: HTTPHeaders = {}; @@ -140,7 +142,12 @@ class PluginGRPCServer { }; this.log.debug('Render request received', 'url', options.url); + call.on('cancelled', (err) => { + this.log.debug('Connection closed', 'url', options.url, 'error', err); + abortController.abort(); + }); let errStr = ''; + try { await this.browser.render(options, signal); } catch (err) { @@ -151,7 +158,8 @@ class PluginGRPCServer { } async renderCsv(call: grpc.ServerUnaryCall, callback: grpc.sendUnaryData) { - const { signal } = new AbortController(); + const abortController = new AbortController(); + const { signal } = abortController; const req = call.request; const headers: HTTPHeaders = {}; @@ -188,6 +196,11 @@ class PluginGRPCServer { }; this.log.debug('Render request received', 'url', options.url); + call.on('cancelled', (err) => { + this.log.debug('Connection closed', 'url', options.url, 'error', err); + abortController.abort(); + }); + let errStr = ''; let fileName = ''; try {