@@ -567,14 +567,15 @@ public void onTimeoutExpired()
567567 LOG .debug ("{} timeouts check" , this );
568568
569569 long now = System .nanoTime ();
570-
570+ long earliest = Long . MAX_VALUE ;
571571 // Reset the earliest timeout so we can expire again.
572572 // A concurrent call to schedule(long) may lose an earliest
573573 // value, but the corresponding exchange is already enqueued
574574 // and will be seen by scanning the exchange queue below.
575- earliestTimeout .set (Long . MAX_VALUE );
575+ earliestTimeout .set (earliest );
576576
577- long earliest = Long .MAX_VALUE ;
577+ // Scan the message queue to abort expired exchanges
578+ // and to find the exchange that expire the earliest.
578579 for (HttpExchange exchange : exchanges )
579580 {
580581 HttpRequest request = exchange .getRequest ();
@@ -596,8 +597,8 @@ private void schedule(long expiresAt)
596597 // Schedule a timeout for the earliest exchange that may expire.
597598 // When the timeout expires, scan the exchange queue for the next
598599 // earliest exchange that may expire, and reschedule a new timeout.
599- long earliest = earliestTimeout .getAndUpdate (t -> Math .min (t , expiresAt ));
600- if (expiresAt < earliest )
600+ long prevEarliest = earliestTimeout .getAndUpdate (t -> Math .min (t , expiresAt ));
601+ if (expiresAt < prevEarliest )
601602 {
602603 // A new request expires earlier than previous requests, schedule it.
603604 long delay = Math .max (0 , expiresAt - System .nanoTime ());
0 commit comments