Skip to content

Commit

Permalink
[ServiceBus] Use Promise.all() when closing connection context. (#1…
Browse files Browse the repository at this point in the history
…8371)

* Use `Promise.all()` when closing connection context so that closing requests are fired immediately.

* Add CHANGELOG entry
  • Loading branch information
jeremymeng authored Nov 5, 2021
1 parent a936695 commit 8752bcf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
2 changes: 2 additions & 0 deletions sdk/servicebus/service-bus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### Bugs Fixed

- Resolves an issue ([#17932](https://github.com/Azure/azure-sdk-for-js/issues/17932)) of receivers not being closed correctly when service bus client is closed.

### Other Changes

## 7.4.0-beta.1 (2021-10-04)
Expand Down
32 changes: 7 additions & 25 deletions sdk/servicebus/service-bus/src/connectionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,37 +617,19 @@ export namespace ConnectionContext {
try {
logger.verbose(`${logPrefix} Permanently closing the amqp connection on the client.`);

// Close all the senders.
const senderNames = Object.keys(context.senders);
logger.verbose(`${logPrefix} Permanently closing ${senderNames.length} senders.`);
for (const senderName of senderNames) {
await context.senders[senderName].close();
}

// Close all MessageReceiver instances
const messageReceiverNames = Object.keys(context.messageReceivers);
logger.verbose(`${logPrefix} Permanently closing ${messageReceiverNames.length} receivers.`);
for (const receiverName of messageReceiverNames) {
await context.messageReceivers[receiverName].close();
}

// Close all MessageSession instances
const messageSessionNames = Object.keys(context.messageSessions);
logger.verbose(
`${logPrefix} Permanently closing ${messageSessionNames.length} session receivers.`
);
for (const messageSessionName of messageSessionNames) {
await context.messageSessions[messageSessionName].close();
}

// Close all the ManagementClients.
const managementClientsEntityPaths = Object.keys(context.managementClients);
logger.verbose(
`${logPrefix} Permanently closing ${managementClientsEntityPaths.length} session receivers.`
`${logPrefix} Permanently closing all the senders(${senderNames.length}), MessageReceivers(${messageReceiverNames.length}), MessageSessions(${messageSessionNames.length}), and ManagementClients(${managementClientsEntityPaths.length}).`
);
for (const entityPath of managementClientsEntityPaths) {
await context.managementClients[entityPath].close();
}
await Promise.all([
...senderNames.map((n) => context.senders[n].close()),
...messageReceiverNames.map((n) => context.messageReceivers[n].close()),
...messageSessionNames.map((n) => context.messageSessions[n].close()),
...managementClientsEntityPaths.map((p) => context.managementClients[p].close())
]);

logger.verbose(`${logPrefix} Permanently closing cbsSession`);
await context.cbsSession.close();
Expand Down

0 comments on commit 8752bcf

Please sign in to comment.