[ruby-core:114013] [Ruby master Bug#18810] Make `Kernel#p` interruptable.
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2023-06-23 10:34:09 UTC
List:
ruby-core #114013
Issue #18810 has been updated by Eregon (Benoit Daloze).
It's because the code changed on master, https://github.com/ruby/ruby/commit/fe6b2e20e9f17ed2c2900aa72994e075ffdc7124 had that bug but master doesn't call `inspect` under `rb_uninterruptible()`.
On master:
```c
static VALUE
rb_f_p(int argc, VALUE *argv, VALUE self)
{
int i;
for (i=0; i<argc; i++) {
VALUE inspected = rb_obj_as_string(rb_inspect(argv[i]));
rb_uninterruptible(rb_p_write, inspected);
}
return rb_p_result(argc, argv);
}
static VALUE
rb_p_result(int argc, const VALUE *argv)
{
VALUE ret = Qnil;
if (argc == 1) {
ret = argv[0];
}
else if (argc > 1) {
ret = rb_ary_new4(argc, argv);
}
VALUE r_stdout = rb_ractor_stdout();
if (RB_TYPE_P(r_stdout, T_FILE)) {
rb_uninterruptible(rb_io_flush, r_stdout);
}
return ret;
}
```
So only the write and the flush are uninterruptible now.
So it does not seem correct to say `Kernel#p is uninterruptible`.
These rb_uninterruptible() seem to have very little effect, indeed it's only if there was a `Thread.handle_interrupt(TimeoutError => :on_blocking)` around the `p` and there is an interrupt and STDOUT is not just a TTY or a file where `write` cannot be interrupted anyway IIRC, then it could happen the interrupt is done during `p`'s `write` (or flush), instead of another blocking call in that block.
I think that's fully expected, we are trying to tweak a corner of a very rare case by making things complicated, it seems not worth it.
----------------------------------------
Bug #18810: Make `Kernel#p` interruptable.
https://bugs.ruby-lang.org/issues/18810#change-103674
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
While figuring out https://bugs.ruby-lang.org/issues/18465 I found a test which fails when `rb_io_flush` becomes blocking.: https://github.com/ruby/ruby/commit/fe6b2e20e9f17ed2c2900aa72994e075ffdc7124
It seems unusual to me that `Kernel#p` is uninterruptible (unique among all Ruby methods). I'd like to make `Kernel#p` interruptible.
--
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/