ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:122613] [Ruby Bug#21456] IO.close does not work in a IO::TimeoutError block.
@ 2025-06-28  7:40 dE (dE Techno) via ruby-core
  2025-07-10  9:23 ` [ruby-core:122717] [Ruby Bug#21456] IO.close does not work in a rescue " nobu (Nobuyoshi Nakada) via ruby-core
  0 siblings, 1 reply; 2+ messages in thread
From: dE (dE Techno) via ruby-core @ 2025-06-28  7:40 UTC (permalink / raw)
  To: ruby-core; +Cc: dE (dE Techno)

Issue #21456 has been reported by dE (dE Techno).

----------------------------------------
Bug #21456: IO.close does not work in a IO::TimeoutError block.
https://bugs.ruby-lang.org/issues/21456

* Author: dE (dE Techno)
* Status: Open
* ruby -v: ruby 3.2.8 (2025-03-26 revision 13f495dc2c) [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Invoking the close method on an IO object based on popen will forcefully close the process (not sure what signal it sends, it's undocumented), however when you handle a IO::TimeoutError exception (which you can get when you set .timeout), the close method fails to end the process. It's going to block until the process naturally terminates.

Sample code (linux based) -- 
execArg = 'echo testwrite; sleep 10'
tofuProcess = IO.popen(execArg, 'r')
puts 'executed tofu process.'
tofuProcess.timeout=5
begin
	tofuOut = tofuProcess.read
rescue IO::TimeoutError
	puts 'rescue occured'
	tofuProcess.close
	puts 'process closed'
end



-- 
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/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:122717] [Ruby Bug#21456] IO.close does not work in a rescue IO::TimeoutError block.
  2025-06-28  7:40 [ruby-core:122613] [Ruby Bug#21456] IO.close does not work in a IO::TimeoutError block dE (dE Techno) via ruby-core
@ 2025-07-10  9:23 ` nobu (Nobuyoshi Nakada) via ruby-core
  0 siblings, 0 replies; 2+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2025-07-10  9:23 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #21456 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Rejected

dE (dE Techno) wrote:
> not sure what signal it sends, it's undocumented

No signal is sent.

Send a signal by yourself if you want to stop the process.
Since your example invokes a grand child process, add `pgroup` option and send "-signal" to the process group.

```ruby
execArg = 'echo testwrite; sleep 10'
tofuProcess = IO.popen(execArg, 'r', pgroup: true) ###
puts 'executed tofu process.'
tofuProcess.timeout=5
begin
  tofuOut = tofuProcess.read
rescue IO::TimeoutError
  puts 'rescue occured'
  Process.kill "-TERM", tofuProcess.pid ###
  tofuProcess.close
  puts 'process closed'
end
```



----------------------------------------
Bug #21456: IO.close does not work in a rescue IO::TimeoutError block.
https://bugs.ruby-lang.org/issues/21456#change-113994

* Author: dE (dE Techno)
* Status: Rejected
* ruby -v: ruby 3.2.8 (2025-03-26 revision 13f495dc2c) [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Invoking the close method on an IO object based on popen will forcefully close the process (not sure what signal it sends, it's undocumented), however when you handle a IO::TimeoutError exception (which you can get when you set .timeout), the close method fails to end the process. It's going to block until the process naturally terminates.

Sample code (linux based) -- 
```ruby
execArg = 'echo testwrite; sleep 10'
tofuProcess = IO.popen(execArg, 'r')
puts 'executed tofu process.'
tofuProcess.timeout=5
begin
	tofuOut = tofuProcess.read
rescue IO::TimeoutError
	puts 'rescue occured'
	tofuProcess.close
	puts 'process closed'
end
```



-- 
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/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-10  9:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-28  7:40 [ruby-core:122613] [Ruby Bug#21456] IO.close does not work in a IO::TimeoutError block dE (dE Techno) via ruby-core
2025-07-10  9:23 ` [ruby-core:122717] [Ruby Bug#21456] IO.close does not work in a rescue " nobu (Nobuyoshi Nakada) via ruby-core

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 NNTP newsgroup(s).