Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
enoeden opened this issue Mar 25, 2025 · 0 comments · May be fixed by #131
Open

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

enoeden opened this issue Mar 25, 2025 · 0 comments · May be fixed by #131

Comments

@enoeden
Copy link

enoeden commented Mar 25, 2025

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.

carlhoerberg added a commit that referenced this issue Mar 26, 2025
To prevent a race condition where the response frame is receivied before
the promise assignment.

Resolves #130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant