From: "ioquatix (Samuel Williams) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "ioquatix (Samuel Williams)" <noreply@ruby-lang.org>
Subject: [ruby-core:117333] [Ruby master Bug#20393] `after_fork_ruby` clears all pending interrupts for both parent and child process.
Date: Tue, 26 Mar 2024 21:10:59 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-107477.20240326211059.3344@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20393.20240326054123.3344@ruby-lang.org
Issue #20393 has been updated by ioquatix (Samuel Williams).
Status changed from Open to Closed
Nobu approved this change on the PR, so I've merged it: https://github.com/ruby/ruby/commit/a7ff264477105b5dc0ade6facad4176a1b73df0b
I'll introduce a separate PR to add the test to ruby-spec.
----------------------------------------
Bug #20393: `after_fork_ruby` clears all pending interrupts for both parent and child process.
https://bugs.ruby-lang.org/issues/20393#change-107477
* Author: ioquatix (Samuel Williams)
* Status: Closed
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
In the following program, the behaviour of the parent process is affected by whether `Process.fork` is invoked or not.
```ruby
Thread.handle_interrupt(RuntimeError => :never) do
Thread.current.raise(RuntimeError, "Queued error")
puts "Pending interrupt: #{Thread.pending_interrupt?}" # true
pid = Process.fork do
puts "Pending interrupt (child process): #{Thread.pending_interrupt?}"
Thread.handle_interrupt(RuntimeError => :immediate){}
end
_, status = Process.waitpid2(pid)
puts "Child process status: #{status.inspect}"
puts "Pending interrupt: #{Thread.pending_interrupt?}" # false
end
puts "Exiting..."
```
I don't think the parent process pending interrupts should be cleared by `after_fork_ruby`:
```c
static void
after_fork_ruby(rb_pid_t pid)
{
rb_threadptr_pending_interrupt_clear(GET_THREAD());
if (pid == 0) {
// child
clear_pid_cache();
rb_thread_atfork();
}
else {
// parent
after_exec();
}
}
```
How about this implementation:
```c
static void
after_fork_ruby(rb_pid_t pid)
{
if (pid == 0) {
// child
rb_threadptr_pending_interrupt_clear(GET_THREAD());
clear_pid_cache();
rb_thread_atfork();
}
else {
// parent
after_exec();
}
}
```
cc @ko1
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/
prev parent reply other threads:[~2024-03-26 21:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 5:41 [ruby-core:117321] [Ruby master Bug#20393] `after_fork_ruby` clears all pending interrupts for both parent and child process ioquatix (Samuel Williams) via ruby-core
2024-03-26 7:53 ` [ruby-core:117323] " ioquatix (Samuel Williams) via ruby-core
2024-03-26 21:10 ` ioquatix (Samuel Williams) via ruby-core [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-107477.20240326211059.3344@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
--cc=noreply@ruby-lang.org \
--cc=ruby-core@ml.ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).