Skip to content

Bug Report: amqp-channel.ts sendRpc Callback Not Triggered Due to Early Server Response #130

@enoeden

Description

@enoeden

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.

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)
})
})
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions