On Thu, 2 Jul 2026 21:45:07 GMT, Benjamin Peterson <[email protected]> 
wrote:

> Make `MinimalFuture` cancelation atomic. This prevents HTTP request 
> cancelation logic from racily completing the future with an error.
> 
> 
> 
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

The problem in the linked bug is that when user of `HttpClient.sendAsync` calls 
`.cancel` on the returned future, the httpclient cancelation logic starts 
running before the future is marked as canceled. That cancelation logic can 
complete the future with an error related to cancelation before the thread that 
prompted the cancelation marks the future as formally canceled. Hence, the 
reproducing program in the bug fails nondeterministically with two possible 
exceptions.

The fix is to mark the future canceled and then start the httpclient 
cancelation logic.

I don't immediately see how there's potential for leaks. Or at least not any 
more potential for leaks than there was before. The cancelation logic is still 
invoked if any thread calls `cancel()`. The difference is now it is guaranteed 
to run at most once.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/31758#issuecomment-4877312515

Reply via email to