diff --git a/sdk/servicebus/service-bus/CHANGELOG.md b/sdk/servicebus/service-bus/CHANGELOG.md index e8dce27a9549..29d9c335fc61 100644 --- a/sdk/servicebus/service-bus/CHANGELOG.md +++ b/sdk/servicebus/service-bus/CHANGELOG.md @@ -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) diff --git a/sdk/servicebus/service-bus/src/connectionContext.ts b/sdk/servicebus/service-bus/src/connectionContext.ts index 1cd781c81b10..e22824cd21be 100644 --- a/sdk/servicebus/service-bus/src/connectionContext.ts +++ b/sdk/servicebus/service-bus/src/connectionContext.ts @@ -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();