@@ -415,6 +415,28 @@ class ControlConnection extends events.EventEmitter {
415415 }
416416 }
417417
418+ async _refreshControlConnection ( hostIterator ) {
419+
420+ if ( this . options . sni ) {
421+ this . connection = this . _borrowAConnection ( hostIterator ) ;
422+ }
423+ else {
424+ try { this . connection = this . _borrowAConnection ( hostIterator ) ; }
425+ catch ( err ) {
426+
427+ /* NODEJS-632: refresh nodes before getting hosts for reconnect since some hostnames may have
428+ * shifted during the flight. */
429+ this . log ( "info" , "ControlConnection could not reconnect using existing connections. Refreshing contact points and retrying" ) ;
430+ this . _contactPoints . clear ( ) ;
431+ this . _resolvedContactPoints . clear ( ) ;
432+ await Promise . all ( this . options . contactPoints . map ( name => this . _parseContactPoint ( name ) ) ) ;
433+ const refreshedContactPoints = Array . from ( this . _contactPoints ) . join ( ',' ) ;
434+ this . log ( 'info' , `Refreshed contact points: ${ refreshedContactPoints } ` ) ;
435+ await this . _initializeConnection ( ) ;
436+ }
437+ }
438+ }
439+
418440 /**
419441 * Acquires a new connection and refreshes topology and keyspace metadata.
420442 * <p>When it fails obtaining a connection and there aren't any more hosts, it schedules reconnection.</p>
@@ -439,8 +461,7 @@ class ControlConnection extends events.EventEmitter {
439461 hostIterator = await promiseUtils . newQueryPlan ( this . _profileManager . getDefaultLoadBalancing ( ) , null , null ) ;
440462 }
441463
442- this . connection = this . _borrowAConnection ( hostIterator ) ;
443-
464+ await this . _refreshControlConnection ( hostIterator ) ;
444465 } catch ( err ) {
445466 // There was a failure obtaining a connection or during metadata retrieval
446467 this . log ( 'error' , 'ControlConnection failed to acquire a connection' , err ) ;
0 commit comments