feat: Bump version to 1.2.2 and improve event emission handling in SMTPOverWSClient to avoid race conditions
This commit is contained in:
parent
6d1070b7e2
commit
180249be26
2 changed files with 10 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@siwats/mxrelay-consumer",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"description": "An internal TypeScript client library for transporting SMTP messages",
|
||||
"main": "lib/index.js",
|
||||
"module": "lib/index.esm.js",
|
||||
|
|
|
@ -859,10 +859,16 @@ export class SMTPOverWSClient extends EventEmitter {
|
|||
data: message.type === 'authenticate_response' ? '[REDACTED]' : (message as any).data,
|
||||
raw: data.length > 200 ? data.substring(0, 200) + '...' : data
|
||||
});
|
||||
// Use setImmediate to avoid catching errors from event handlers
|
||||
|
||||
// Emit authentication events immediately to avoid race conditions
|
||||
if (message.type === SMTPOverWsMessageType.AUTHENTICATE_RESPONSE) {
|
||||
(this as any).emit(message.type, message);
|
||||
} else {
|
||||
// Use setImmediate for other events to avoid catching errors from event handlers
|
||||
setImmediate(() => {
|
||||
(this as any).emit(message.type, message);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to parse WebSocket message', { data, error });
|
||||
this.emit('error', ErrorFactory.protocolError('Invalid message format', undefined, { data }));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue