mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-28 05:59:42 -08:00
fix(core): Handle websocket connection error more gracefully in task runners (#11635)
This commit is contained in:
parent
835fbfe337
commit
af7d6e68d0
|
@ -1,4 +1,4 @@
|
|||
import { ApplicationError } from 'n8n-workflow';
|
||||
import { ApplicationError, ensureError } from 'n8n-workflow';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { type MessageEvent, WebSocket } from 'ws';
|
||||
|
||||
|
@ -88,6 +88,24 @@ export abstract class TaskRunner {
|
|||
},
|
||||
maxPayload: opts.maxPayloadSize,
|
||||
});
|
||||
|
||||
this.ws.addEventListener('error', (event) => {
|
||||
const error = ensureError(event.error);
|
||||
|
||||
if (
|
||||
'code' in error &&
|
||||
typeof error.code === 'string' &&
|
||||
['ECONNREFUSED', 'ENOTFOUND'].some((code) => code === error.code)
|
||||
) {
|
||||
console.error(
|
||||
`Error: Failed to connect to n8n. Please ensure n8n is reachable at: ${opts.n8nUri}`,
|
||||
);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.error(`Error: Failed to connect to n8n at ${opts.n8nUri}`);
|
||||
console.error('Details:', event.message || 'Unknown error');
|
||||
}
|
||||
});
|
||||
this.ws.addEventListener('message', this.receiveMessage);
|
||||
this.ws.addEventListener('close', this.stopTaskOffers);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue