10000 merge revision(s) 5f77f9bea61fb4cc8447a76e191fdfb28f076862: [Backport… · github/ruby@51dee04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51dee04

Browse files
committed
merge revision(s) 5f77f9b: [Backport #21195]
Fix handling of `error`/`errno` in `io_internal_wait`. (ruby#12961) [Bug #21195]
1 parent aac5c54 commit 51dee04

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

io.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,14 @@ io_internal_wait(VALUE thread, rb_io_t *fptr, int error, int events, struct time
11561156
return -1;
11571157
}
11581158

1159-
errno = error;
1160-
return -1;
1159+
// If there was an error BEFORE we started waiting, return it:
1160+
if (error) {
1161+
errno = error;
1162+
return -1;
1163+
} else {
1164+
// Otherwise, whatever error was generated by `nogvl_wait_for` is the one we want:
1165+
return ready;
1166+
}
11611167
}
11621168

11631169
static VALUE

test/ruby/test_io.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4297,4 +4297,30 @@ def test_stdout_to_closed_pipe
42974297
end
42984298
end
42994299
end
4300+
4301+
def test_blocking_timeout
4302+
assert_separately([], <<~'RUBY')
4303+
IO.pipe do |r, w|
4304+
trap(:INT) do
4305+
w.puts "INT"
4306+
end
4307+
4308+
main = Thread.current
4309+
thread = Thread.new do
4310+
# Wait until the main thread has entered `$stdin.gets`:
4311+
Thread.pass until main.status == 'sleep'
4312+
4313+
# Cause an interrupt while handling `$stdin.gets`:
4314+
Process.kill :INT, $$
4315+
end
4316+
4317+
r.timeout = 1
4318+
assert_equal("INT", r.gets.chomp)
4319+
rescue IO::TimeoutError
4320+
# Ignore - some platforms don't support interrupting `gets`.
4321+
ensure
4322+
thread&.join
4323+
end
4324+
RUBY
4325+
end
43004326
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 7
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 138
14+
#define RUBY_PATCHLEVEL 139
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)
0