Skip to content

Commit

Permalink
Merge pull request #115 from jeremymeng/cleanup-when-createreceiver-t…
Browse files Browse the repository at this point in the history
…imeout

Fix an issue where links are kept alive
  • Loading branch information
jeremymeng authored Jun 11, 2024
2 parents 6ff5c9c + 079af75 commit 867e5fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.0.3 - (2024-06-12)

- Release the resources if `Session.createReceiver()` rejects due to timeout.

### 3.0.2 - (2024-05-02)

- Set the max listener limit to 1000 for `RheaConnection`
Expand Down
11 changes: 10 additions & 1 deletion lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License. See License in the project root for license information.

import * as log from "./log";
import { Connection } from "./connection";
import { Connection, CreateReceiverOptions } from "./connection";
import { Receiver, ReceiverOptions } from "./receiver";
import { Sender, SenderOptions } from "./sender";
import {
Expand Down Expand Up @@ -396,6 +396,15 @@ export class Session extends Entity {
const msg: string = `Unable to create the amqp receiver '${receiver.name}' on amqp ` +
`session '${this.id}' due to operation timeout.`;
log.error("[%s] %s", this.connection.id, msg);

const createReceiverOptions = options as CreateReceiverOptions;
if (createReceiverOptions?.session?.createReceiver) {
// being called on a session passed via the options so don't close the session
receiver.close({ closeSession: false }).then(() => { receiver.remove(); })
} else {
receiver.close({ closeSession: true }).then(() => { receiver.remove(); })
}

return reject(new OperationTimeoutError(msg));
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rhea-promise",
"version": "3.0.2",
"version": "3.0.3",
"description": "A Promisified layer over rhea AMQP client",
"license": "Apache-2.0",
"main": "./dist/lib/index.js",
Expand Down

0 comments on commit 867e5fc

Please sign in to comment.