ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "byroot (Jean Boussier) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "byroot (Jean Boussier)" <noreply@ruby-lang.org>
Subject: [ruby-core:114835] [Ruby master Bug#19624] Backticks - IO object leakage
Date: Wed, 20 Sep 2023 12:00:24 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-104679.20230920120023.52810@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19624.20230430145637.52810@ruby-lang.org

Issue #19624 has been updated by byroot (Jean Boussier).





@nobu Interesting. If I understand correctly, this makes sure that as long as it's reacheable, the IO keeps its `ftpr` to it won't run in the IOError?



If so yes that seems like a much cleaner solution than hiding it.



----------------------------------------

Bug #19624: Backticks - IO object leakage

https://bugs.ruby-lang.org/issues/19624#change-104679



* Author: pineman (João Pinheiro)

* Status: Closed

* Priority: Normal

* ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]

* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN

----------------------------------------

Hi,



This code works on ruby 3.0.6:



```ruby

`echo`

ObjectSpace.each_object(IO) do |io|

  if ![STDIN, STDOUT, STDERR].include?(io)

    io.close

  end

end

```

but raises `IOError` on 3.2.2:

```

minimal-repro-case.rb:8:in `close': uninitialized stream (IOError)

```





I found it started failing on ruby 3.1.0 and after, on macOS and Linux.

This code is useful for closing unneeded IO objects in forked processes.

It looks like backticks is 'leaking' IO objects, waiting for GC, and it didn't used to before 3.1.0.

In ruby 3.1.0, inside `rb_f_backquote` in `io.c`, `rb_gc_force_recycle` was removed in favor of `RB_GC_GUARD` (commit `aeae6e2842e`). I wonder if this has something to do with the problem.

Is this code incorrect since ruby 3.1.0 or is it a bug in ruby?

Thanks.



---Files--------------------------------

minimal-repro-case.rb (109 Bytes)





-- 

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/

  parent reply	other threads:[~2023-09-20 12:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-30 14:56 [ruby-core:113381] [Ruby master Bug#19624] Backticks - IO object leakage pineman via ruby-core
2023-09-20  9:14 ` [ruby-core:114829] " byroot (Jean Boussier) via ruby-core
2023-09-20 11:16 ` [ruby-core:114832] " Eregon (Benoit Daloze) via ruby-core
2023-09-20 11:18 ` [ruby-core:114833] " byroot (Jean Boussier) via ruby-core
2023-09-20 11:57 ` [ruby-core:114834] " nobu (Nobuyoshi Nakada) via ruby-core
2023-09-20 12:00 ` byroot (Jean Boussier) via ruby-core [this message]
2023-09-20 12:52 ` [ruby-core:114837] " nobu (Nobuyoshi Nakada) via ruby-core
2023-09-20 13:01 ` [ruby-core:114838] " byroot (Jean Boussier) via ruby-core
2023-09-20 14:54 ` [ruby-core:114841] " nobu (Nobuyoshi Nakada) via ruby-core
2023-09-20 15:21 ` [ruby-core:114842] " byroot (Jean Boussier) via ruby-core

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-104679.20230920120023.52810@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).