Skip to content

Process.kill to yourself: Interrupt for INT, MRI's default after a trap - #161

Merged
Largo merged 1 commit into
masterfrom
claude/self-sigint-interrupt
Nov 8, 2026
Merged

Largo merged 1 commit into
masterfrom
claude/self-sigint-interrupt

Conversation

@Largo

@Largo Largo commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Found while testing #154 on Windows: a check that sent INT to its own process got SignalException instead of Interrupt. Older than #154 and unrelated to it.

What changes

When a process signals itself, Process.kill stands in for the signal rather than letting the real one kill .NET. That stand-in now matches CRuby 4.0 (checked against ruby 4.0.9 on Linux and ruby 4.0.5 x64-mingw-ucrt on Windows):

Process.kill(sig, Process.pid), no trap CRuby 4.0 IronRuby before after
INT Interrupt, message "", signo 2 SignalException "SIGINT" (Windows; Linux gave Interrupt with message "Interrupt") Interrupt, "", 2
HUP / TERM / QUIT / USR1 / USR2 / ALRM SignalException "SIGxxx" same same
PIPE / SYS / VTALRM nothing happens SignalException nothing happens
TERM after old = trap(:TERM) {...}; trap(:TERM, old) SignalException swallowed (the trap left an empty "DEFAULT" entry behind) SignalException
TERM after trap(:TERM, "SYSTEM_DEFAULT") process dies (143) swallowed process dies (143)
  • RubyProcess.Kill: raises Interrupt("") for INT; skips PIPE/SYS/VTALRM; treats a signal trapped back to DEFAULT or SYSTEM_DEFAULT as untrapped (PosixSignals.HasRubyHandler), and lets SYSTEM_DEFAULT go to the real kill(2).
  • Ctrl-C (Program.cs) and trap(:INT, "DEFAULT") (Signal.cs) raise Interrupt with the same empty message CRuby uses. An uncaught one still prints Interrupt and exits 130, as CRuby does.

Tests

  • New Process_KillSelfInterrupt1; its expected output is CRuby 4.0's output for the same script.
  • IronRuby.Tests, Debug net8.0: all passed on Linux, and on Windows (spinel-windows VM, 1093 tests run, password ssh).
  • mspec on Linux: core/process/kill_spec.rb, core/signal, core/exception/interrupt_spec.rb, core/exception/signal_exception_spec.rb: 93 examples, 0 failures.

Not changed

  • On Windows, trap(:TERM, "SYSTEM_DEFAULT") followed by a self-kill still does nothing (CRuby ends the process). The Windows self-kill path has no real signal to send.
  • Signals that CRuby leaves at the OS default (TRAP, XCPU, XFSZ, PROF, IO, PWR, ...) end a CRuby process that sends them to itself. IronRuby still raises SignalException for them.
  • IronRuby's Signal.list on Windows has all the POSIX names. CRuby on Windows lists only EXIT, INT, ILL, ABRT, FPE, KILL, SEGV, TERM.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Self-sent SIGINT now raises an interrupt with an empty message, while other terminating signals raise a signal exception unless a handler or system-default trap applies.
    • Signals ignored by default, including PIPE, SYS, and VTALRM, are now skipped when sent to the current process.
    • Restoring a trapped signal to "DEFAULT" restores its default handling behavior.

A process that signalled itself with SIGINT and had no handler got a
SignalException ("SIGINT"), which `rescue Interrupt` does not catch. MRI
raises Interrupt, with an empty message and #signo 2; the Ctrl-C and
trap(:INT, "DEFAULT") paths now use the same empty message.

PIPE, SYS and VTALRM, which MRI swallows unless trapped, raised a
SignalException; sending one of them to yourself is now a no-op.

A signal trapped back to "DEFAULT" (trap(:TERM, old)) was swallowed by
the empty handler entry the trap left behind; it raises SignalException
again, and "SYSTEM_DEFAULT" goes to the real kill(2) as in MRI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Self-signal handling now distinguishes Ruby handlers and system-default traps from default behavior. SIGINT raises Interrupt with an empty message, while default-ignored signals are skipped. Tests cover these cases and verify signal exception details.

Changes: Self-signal handling

Layer / File(s) Summary
Signal classification
Src/Libraries/Builtins/PosixSignals.cs
PosixSignals defines the SIGINT constant, classifies PIPE, VTALRM, and SYS as ignored by default, and distinguishes Ruby handlers from system-default traps.
Self-signal flow and validation
Src/Libraries/Builtins/RubyProcess.cs, Src/Libraries/Builtins/Signal.cs, Src/Console/Program.cs, Src/IronRuby.Tests/Runtime/MiscTests.cs, Src/IronRuby.Tests/RubyTests.cs
RubyProcess.Kill uses the signal classifications for self-signals. SIGINT creates an Interrupt with an empty message; other default-terminating signals raise SignalException, and default-ignored signals are skipped. The registered test checks these behaviors and signal trap restoration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RubyCaller
  participant RubyProcessKill
  participant PosixSignals
  participant RubyHandler
  RubyCaller->>RubyProcessKill: Call Kill with a signal for the current process
  RubyProcessKill->>PosixSignals: Check Ruby handler and system-default trap
  PosixSignals-->>RubyProcessKill: Return stored handler state
  alt Ruby handler is present
    RubyProcessKill->>RubyHandler: Run handler immediately on the main thread
  else No Ruby handler or system-default trap
    RubyProcessKill-->>RubyCaller: Raise Interrupt for SIGINT or SignalException for other default-terminating signals
  end
Loading

Suggested reviewers: claude, sholden

Merge Risk: Minimal · up to 41c78

No actionable merge-blocking issue was established in the self-signal changes. The change is ready for normal validation.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main behavior change: self-sent INT in Process.kill now raises Interrupt, matching MRI's default after a trap. The changeset supports this. RubyProcess.Kill raises Interrupt for SI…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main behavior change: self-sent INT in Process.kill now raises Interrupt, matching MRI's default after a trap. The changeset supports this. RubyProcess.Kill raises Interrupt for SIGINT with no Ruby handler or OS-default trap, Signal.cs creates Interrupt with an empty message, and MiscTests.cs adds Process_KillSelfInterrupt1 to check the empty message and signal number 2. The title omits the secondary changes, such as PIPE, SYS, and VTALRM becoming no-ops and SYSTEM_DEFAULT handling, but it does not need to cover every detail. The title is specific and uses no vague terms, though its colon-separated phrasing is somewhat dense.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 32970ac and 41c78e6.

Files selected for processing: 6

  • Src/Console/Program.cs
  • Src/IronRuby.Tests/RubyTests.cs
  • Src/IronRuby.Tests/Runtime/MiscTests.cs
  • Src/Libraries/Builtins/PosixSignals.cs
  • Src/Libraries/Builtins/RubyProcess.cs
  • Src/Libraries/Builtins/Signal.cs

Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

@Largo
Largo merged commit 1590ab0 into master Nov 8, 2026
8 checks passed
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