Add abandonOnInterrupt utilities for uninterruptible blocking operations#479
Merged
Conversation
Uninterruptible operations (classic java.io stream reads/writes, DNS resolution, JDBC calls etc.) don't respond to Thread.interrupt, so forks blocked in them ignore scope cancellation. The new utilities delegate such operations to detached (unmanaged, never-joined) virtual threads, while the calling fork awaits the result interruptibly; on interruption, the operation is abandoned, optionally closing the underlying resource: - abandonOnInterrupt: one-off blocking calls, with optional onAbandon cleanup - abandonOnInterruptReads/abandonOnInterruptWrites: InputStream and OutputStream wrappers, proxying data through a rendezvous channel Also: document which operations are (un)interruptible on the JVM, with sources, in the interruptions doc page, which absorbs the former best-practices stdin section. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uninterruptible operations (classic
java.iostream reads/writes, DNS resolution, JDBC calls etc.) don't respond toThread.interrupt, so forks blocked in them ignore scope cancellation. The new utilities delegate such operations to detached (unmanaged, never-joined) virtual threads, while the calling fork awaits the result interruptibly; on interruption, the operation is abandoned — its result is given up — optionally closing the underlying resource:abandonOnInterrupt(op)(onAbandon): one-off blocking calls, with optional cleanup started on abandonment (e.g.abandonOnInterrupt(statement.execute())(connection.close()))abandonOnInterruptReads/abandonOnInterruptWrites:InputStream/OutputStreamwrappers proxying data through a rendezvous channel; an interrupted read doesn't lose the in-flight chunk, andcloseOnAbandon = truecloses the underlying stream terminallyAlso documents which JVM operations are (un)interruptible, with sources, on the interruptions doc page — which absorbs the former best-practices stdin section (the stdin workaround is now
abandonOnInterruptReads(System.in)).The API is purely additive (MiMa passes without new filters). Re-applies 0c244e4, which was pushed to master by mistake and reverted in a94eef0.
🤖 Generated with Claude Code