Skip to content

Commit 079af75

Browse files
committed
Fix an issue where links are kept alive
even though we are unable to create an Amqp receiver due to operation timeout. The problem is that `rheaReceiver` and `receiver` are created when the Promise instance is created, however, they are not removed when rejecting due to operation timeout. So the created objects are kept by `rhea` as long as the connection is alive. In this case there's no way for outside caller to do the clean up because `receiver` is not returned by the `resolve` callback. This PR adds cleanup for the `actionAfterTimeout` code path.
1 parent 6ff5c9c commit 079af75

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 3.0.3 - (2024-06-12)
2+
3+
- Release the resources if `Session.createReceiver()` rejects due to timeout.
4+
15
### 3.0.2 - (2024-05-02)
26

37
- Set the max listener limit to 1000 for `RheaConnection`

lib/session.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License. See License in the project root for license information.
33

44
import * as log from "./log";
5-
import { Connection } from "./connection";
5+
import { Connection, CreateReceiverOptions } from "./connection";
66
import { Receiver, ReceiverOptions } from "./receiver";
77
import { Sender, SenderOptions } from "./sender";
88
import {
@@ -396,6 +396,15 @@ export class Session extends Entity {
396396
const msg: string = `Unable to create the amqp receiver '${receiver.name}' on amqp ` +
397397
`session '${this.id}' due to operation timeout.`;
398398
log.error("[%s] %s", this.connection.id, msg);
399+
400+
const createReceiverOptions = options as CreateReceiverOptions;
401+
if (createReceiverOptions?.session?.createReceiver) {
402+
// being called on a session passed via the options so don't close the session
403+
receiver.close({ closeSession: false }).then(() => { receiver.remove(); })
404+
} else {
405+
receiver.close({ closeSession: true }).then(() => { receiver.remove(); })
406+
}
407+
399408
return reject(new OperationTimeoutError(msg));
400409
};
401410

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rhea-promise",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"description": "A Promisified layer over rhea AMQP client",
55
"license": "Apache-2.0",
66
"main": "./dist/lib/index.js",

0 commit comments

Comments
 (0)