Skip to content
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

[ServiceBus] Use Promise.all() when closing connection context. #18371

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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