-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Description
When calling channel.open(), the sendRpc method attempts to assign this.resolveRPC after sending data. However, in some cases, the server may respond before this.resolveRPC is assigned, leading to a stuck (hanging) Promise.
amqp-client.js/src/amqp-channel.ts
Lines 743 to 754 in d1177f5
| private sendRpc(frame: AMQPView, frameSize: number): Promise<any> { | |
| return new Promise((resolve, reject) => { | |
| this.rpcQueue = this.rpcQueue.then(() => { | |
| this.connection.send(new Uint8Array(frame.buffer, 0, frameSize)) | |
| .then(() => { | |
| this.resolveRPC = resolve | |
| this.rejectRPC = reject | |
| }) | |
| .catch(reject) | |
| }) | |
| }) | |
| } |
amqp-client.js/src/amqp-base-client.ts
Lines 332 to 338 in d1177f5
| case 20: { // channel | |
| switch (methodId) { | |
| case 11: { // openok | |
| i += 4 // reserved1 (long string) | |
| channel.resolveRPC(channel) | |
| break | |
| } |
channel.resolveRPC(channel) may never get called in a correct way and cause the channel open method hang forever
Issue:
The server may respond immediately after send(), before this.resolveRPC is assigned.
If this happens, the expected callback never gets executed, causing the Promise to hang indefinitely.
Suggested Fix
Instead of assigning this.resolveRPC after sending the frame, assign it before.