@@ -567,14 +567,15 @@ public void onTimeoutExpired()
567
567
LOG .debug ("{} timeouts check" , this );
568
568
569
569
long now = System .nanoTime ();
570
-
570
+ long earliest = Long . MAX_VALUE ;
571
571
// Reset the earliest timeout so we can expire again.
572
572
// A concurrent call to schedule(long) may lose an earliest
573
573
// value, but the corresponding exchange is already enqueued
574
574
// and will be seen by scanning the exchange queue below.
575
- earliestTimeout .set (Long . MAX_VALUE );
575
+ earliestTimeout .set (earliest );
576
576
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.
578
579
for (HttpExchange exchange : exchanges )
579
580
{
580
581
HttpRequest request = exchange .getRequest ();
@@ -596,8 +597,8 @@ private void schedule(long expiresAt)
596
597
// Schedule a timeout for the earliest exchange that may expire.
597
598
// When the timeout expires, scan the exchange queue for the next
598
599
// 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 )
601
602
{
602
603
// A new request expires earlier than previous requests, schedule it.
603
604
long delay = Math .max (0 , expiresAt - System .nanoTime ());
0 commit comments