[concurrency-interest] CompletableFuture.get() swallows thread interrupt flag on Java 11

David Holmes davidcholmes at aapt.net.au
Thu Oct 15 03:55:09 EDT 2020


I think I can see how this happens. At the end of waitingGet we may have been interrupted and already caught the IE, but because we are interruptible we don't re-assert the interrupt status. If we return null that indicates reportGet should throw IE. But before we return from waitingGet we reload from "result" which may now be non-null, so we return non-null and hence never rethrow the IE.

There needs to be a further check of q.interrupted and a re-assertion of the interrupt state, but I'm not certain of the exact state that needs to be checked. Possibly:

If (r != null || (r = result) != null) {
  postComplete();
 + if (q != null && q.interrupted && interruptible)
 +   Thread.currentThread().interrupt();
}

Cheers,
David

-----Original Message-----
From: Concurrency-interest <concurrency-interest-bounces at cs.oswego.edu> On Behalf Of Jens Wilke via Concurrency-interest
Sent: Thursday, 15 October 2020 5:02 PM
To: Alex Otenko <oleksandr.otenko at gmail.com>
Cc: concurrency-interest <concurrency-interest at cs.oswego.edu>
Subject: Re: [concurrency-interest] CompletableFuture.get() swallows thread interrupt flag on Java 11

No. Interruption works.

The problem is triggered when interruption and completion happen at the 
same time.

On 15/10/20 4:23 pm, Alex Otenko wrote:
> Does it reproduce if you remove the line that completes the future?
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest



More information about the Concurrency-interest mailing list