Skip to content

fix: avoid panic when attempting to use test server across fork#408

Merged
chris-olszewski merged 3 commits intomainfrom
olszewski/fix_rails_parallel
Apr 1, 2026
Merged

fix: avoid panic when attempting to use test server across fork#408
chris-olszewski merged 3 commits intomainfrom
olszewski/fix_rails_parallel

Conversation

@chris-olszewski
Copy link
Copy Markdown
Member

What was changed

Avoid dropping the tokio runtime if we're in a fork.

Why?

We document that objects that hold this runtime handle cannot be used across threads and throw specific errors explaining this if it is attempted

def test_fork
# Cannot use client on other side of fork from where created
pre_fork_client = env.client
pid = fork do
pre_fork_client.start_workflow(
'some-workflow', id: "wf-#{SecureRandom.uuid}", task_queue: "tq-#{SecureRandom.uuid}"
)
rescue Temporalio::Internal::Bridge::Error => e
exit! 123 if e.message.start_with?('Cannot use client across forks')
raise
end
_, status = Process.wait2(pid)
assert_equal 123, status.exitstatus

The issue is that these useful errors can be hidden by a panic from dropping the runtime handle which allows the expected errors to surface to users.

Checklist

  1. Closes [Bug] Parallel test configuration in Rails causes crash #407

  2. How was this tested:
    Initial commit added failing test. Tested with Configure parallel tests in rails app (which doesn't work - yet) samples-ruby#78 (review) and verified that the errors explaining invalid usage across forks are now displayed instead of a panic.

  3. Any docs updates needed?
    N/A

Reproduces temporalio/samples-ruby#78: when a process forks after a
Temporal runtime is created (e.g., Rails parallelize) and the child
exits with `exit` (triggering Ruby's object finalization), the Rust
Drop for CoreRuntime tries to shut down Tokio, which wakes the I/O
driver using inherited (now invalid) kqueue/epoll FDs — causing a
panic: "failed to wake I/O driver: Bad file descriptor".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

squash
@chris-olszewski chris-olszewski requested a review from a team as a code owner April 1, 2026 15:04
@chris-olszewski chris-olszewski merged commit bcc7510 into main Apr 1, 2026
7 checks passed
@chris-olszewski chris-olszewski deleted the olszewski/fix_rails_parallel branch April 1, 2026 15:40
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.

[Bug] Parallel test configuration in Rails causes crash

2 participants