@@ -2,7 +2,7 @@ import * as os from "os";
22import * as BluebirdPromise from "bluebird" ;
33import * as semaphore from "semaphore" ;
44import * as stream from "readable-stream" ;
5- import { acquireSemaphore } from "../Utility/SemaphoreUtil" ;
5+ import { acquireSemaphore , AcquiredSemaphoreContext } from "../Utility/SemaphoreUtil" ;
66import { getLogger , ILogger } from "../Utility/LogUtil" ;
77import { Timer } from "../Primitives/Timer" ;
88import { ServerNode } from "./ServerNode" ;
@@ -326,54 +326,53 @@ export class RequestExecutor implements IDisposable {
326326 return this . _nodeSelector . getFastestNode ( ) ;
327327 }
328328
329- protected _updateClientConfiguration ( ) : PromiseLike < void > {
330- if ( this . _disposed ) {
331- return BluebirdPromise . resolve ( null ) ;
332- }
329+ private async _updateClientConfigurationInternal ( ) : Promise < void > {
330+ const oldDisableClientConfigurationUpdates = this . _disableClientConfigurationUpdates ;
331+ this . _disableClientConfigurationUpdates = true ;
333332
334- const updateClientConfigurationInternal = ( ) => {
335- const oldDisableClientConfigurationUpdates = this . _disableClientConfigurationUpdates ;
336- this . _disableClientConfigurationUpdates = true ;
333+ try {
334+ if ( this . _disposed ) {
335+ return ;
336+ }
337337
338- return BluebirdPromise . resolve ( )
339- . then ( ( ) => {
338+ const command = new GetClientConfigurationCommand ( ) ;
339+ const { currentNode, currentIndex } = this . chooseNodeForRequest ( command , null ) ;
340+ await this . execute ( command , null , {
341+ chosenNode : currentNode ,
342+ nodeIndex : currentIndex ,
343+ shouldRetry : false
344+ } ) ;
340345
341- if ( this . _disposed ) {
342- return ;
343- }
346+ const clientConfigOpResult = command . result ;
347+ if ( ! clientConfigOpResult ) {
348+ return ;
349+ }
344350
345- const command = new GetClientConfigurationCommand ( ) ;
346- const currentIndexAndNode2 : CurrentIndexAndNode = this . chooseNodeForRequest ( command , null ) ;
347- return this . execute ( command , null , {
348- chosenNode : currentIndexAndNode2 . currentNode ,
349- nodeIndex : currentIndexAndNode2 . currentIndex ,
350- shouldRetry : false
351- } )
352- . then ( ( ) => command . result ) ;
353- } )
354- . then ( ( clientConfigOpResult : GetClientConfigurationOperationResult ) => {
355- if ( ! clientConfigOpResult ) {
356- return ;
357- }
351+ this . _conventions . updateFrom ( clientConfigOpResult . configuration ) ;
352+ this . _clientConfigurationEtag = clientConfigOpResult . etag ;
353+ } catch ( err ) {
354+ this . _log . error ( err , "Error getting client configuration." ) ;
355+ } finally {
356+ this . _disableClientConfigurationUpdates = oldDisableClientConfigurationUpdates ;
357+ }
358+ }
358359
359- this . _conventions . updateFrom ( clientConfigOpResult . configuration ) ;
360- this . _clientConfigurationEtag = clientConfigOpResult . etag ;
360+ protected async _updateClientConfiguration ( ) : Promise < void > {
361+ if ( this . _disposed ) {
362+ return ;
363+ }
361364
362- } )
363- . tapCatch ( err => this . _log . error ( err , "Error getting client configuration." ) )
364- . finally ( ( ) => {
365- this . _disableClientConfigurationUpdates = oldDisableClientConfigurationUpdates ;
366- } ) ;
367- } ;
365+ let semAcquiredContext : AcquiredSemaphoreContext ;
368366
369- const semAcquiredContext = acquireSemaphore ( this . _updateClientConfigurationSemaphore ) ;
370- const result = BluebirdPromise . resolve ( semAcquiredContext . promise )
371- . then ( ( ) => updateClientConfigurationInternal ( ) )
372- . finally ( ( ) => {
367+ try {
368+ semAcquiredContext = acquireSemaphore ( this . _updateClientConfigurationSemaphore ) ;
369+ await semAcquiredContext . promise ;
370+ await this . _updateClientConfigurationInternal ( ) ;
371+ } finally {
372+ if ( semAcquiredContext ) {
373373 semAcquiredContext . dispose ( ) ;
374- } ) ;
375-
376- return Promise . resolve ( result ) ;
374+ }
375+ }
377376 }
378377
379378 public updateTopology ( node : ServerNode , timeout : number , forceUpdate : boolean = false ) : Promise < boolean > {
0 commit comments