Skip to content

Commit

Permalink
fix: process unable to exit after connect
Browse files Browse the repository at this point in the history
The process is kept alive after connect until the connect
timeout has been fired/cancelled.
  • Loading branch information
luddd3 committed Feb 5, 2022
1 parent 49823c4 commit 8d572b1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/AmqpConnectionManager.ts
Expand Up @@ -225,22 +225,27 @@ export default class AmqpConnectionManager extends EventEmitter implements IAmqp
}
};

let waitTimeout;
if (timeout) {
waitTimeout = wait(timeout);
}
try {
await Promise.race([
once(this, 'connect'),
new Promise((_resolve, innerReject) => {
reject = innerReject;
this.on('connectFailed', onConnectFailed);
}),
...(timeout
...(waitTimeout
? [
wait(timeout).promise.then(() => {
waitTimeout.promise.then(() => {
throw new Error('amqp-connection-manager: connect timeout');
}),
]
: []),
]);
} finally {
waitTimeout?.cancel();
this.removeListener('connectFailed', onConnectFailed);
}
}
Expand Down

0 comments on commit 8d572b1

Please sign in to comment.