Skip to content

Add abandonOnInterrupt utilities for uninterruptible blocking operations#479

Merged
adamw merged 2 commits into
masterfrom
abandon-on-interrupt
Jul 19, 2026
Merged

Add abandonOnInterrupt utilities for uninterruptible blocking operations#479
adamw merged 2 commits into
masterfrom
abandon-on-interrupt

Conversation

@adamw

@adamw adamw commented Jul 19, 2026

Copy link
Copy Markdown
Member

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 — 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 / OutputStream wrappers proxying data through a rendezvous channel; an interrupted read doesn't lose the in-flight chunk, and closeOnAbandon = true closes the underlying stream terminally

Also 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

adamw and others added 2 commits July 19, 2026 20:28
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>
@adamw
adamw merged commit 2b2d03d into master Jul 19, 2026
6 checks passed
@adamw
adamw deleted the abandon-on-interrupt branch July 19, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant