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 2 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
33 changes: 8 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,20 @@ 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, MessageReceivers, MessageSessions, and ManagementClients.`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include the count in paranthesis perhaps? That way we retain that info?

Permanently closing all the senders(4), MessageReceivers(3), MessageSessions(0), and ManagementClients(1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that could be useful.

);
for (const entityPath of managementClientsEntityPaths) {
await context.managementClients[entityPath].close();
}
const managementClientsEntityPaths = Object.keys(context.managementClients);
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