3939import java .time .Clock ;
4040import java .time .Duration ;
4141import java .time .Instant ;
42+ import java .time .temporal .ChronoUnit ;
4243import java .util .BitSet ;
4344import java .util .EnumSet ;
4445import java .util .HashMap ;
@@ -417,14 +418,15 @@ void setPool(SessionPool pool) {
417418 }
418419
419420 private void maybeWaitForSessionCreation (
420- SessionPoolOptions sessionPoolOptions , SettableApiFuture <SessionReference > initialSessionReferenceFuture ) {
421+ SessionPoolOptions sessionPoolOptions ,
422+ SettableApiFuture <SessionReference > initialSessionReferenceFuture ) {
421423 Duration waitDuration = sessionPoolOptions .getWaitForMinSessions ();
422424 SpannerException lastException = null ;
423425 SettableApiFuture <SessionReference > sessionReferenceFuture = initialSessionReferenceFuture ;
424426
425427 if (waitDuration != null && !waitDuration .isZero ()) {
426- Instant endTime = Instant .now ().plus (waitDuration );
427- while (Instant .now ().isBefore (endTime )) {
428+ Instant endTime = Instant .now ().plus (waitDuration ). truncatedTo ( ChronoUnit . MILLIS ) ;
429+ while (Instant .now ().truncatedTo ( ChronoUnit . MILLIS ). isBefore (endTime )) {
428430 // If any exception is thrown, then retry the multiplexed session creation
429431 if (sessionReferenceFuture == null ) {
430432 sessionReferenceFuture = SettableApiFuture .create ();
@@ -434,7 +436,7 @@ private void maybeWaitForSessionCreation(
434436 // Calculate the remaining time pending for the future to wait for multiplexed session
435437 Duration remainingTime = Duration .between (Instant .now (), endTime );
436438 System .out .println ("Is ended: " + Instant .now ().isBefore (endTime ));
437- System .out .println ("Remaining time: " + remainingTime .toMillis ());
439+ System .out .println ("Remaining time: " + remainingTime .toNanos ());
438440 try {
439441 sessionReferenceFuture .get (remainingTime .toMillis (), TimeUnit .MILLISECONDS );
440442 lastException = null ;
0 commit comments