[#113107] [Ruby master Bug#19576] Backport request: Gemfile.lock resolving is broken with bundler shipped with Ruby 3.1.4 — "jprokop (Jarek Prokop) via ruby-core" <ruby-core@...>

Issue #19576 has been reported by jprokop (Jarek Prokop).

8 messages 2023/04/04

[#113112] [Ruby master Bug#19578] abort() shows stack trace when run within rescue clause — "Dan0042 (Daniel DeLorme) via ruby-core" <ruby-core@...>

Issue #19578 has been reported by Dan0042 (Daniel DeLorme).

8 messages 2023/04/04

[#113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification — "kyanagi (Kouhei Yanagita) via ruby-core" <ruby-core@...>

Issue #19588 has been reported by kyanagi (Kouhei Yanagita).

7 messages 2023/04/11

[#113209] [Ruby master Bug#19596] Decreased performance after upgrading from ruby 2.7.2 to ruby 3.2.2 — silva96 via ruby-core <ruby-core@...>

Issue #19596 has been reported by silva96 (Benjam=EDn Silva).

7 messages 2023/04/13

[#113238] [Ruby master Misc#19599] DevMeeting-2023-05-10 — "mame (Yusuke Endoh) via ruby-core" <ruby-core@...>

Issue #19599 has been reported by mame (Yusuke Endoh).

14 messages 2023/04/14

[#113285] [Ruby master Bug#19607] Introduce `Hash#symbolize_keys`. — "ioquatix (Samuel Williams) via ruby-core" <ruby-core@...>

Issue #19607 has been reported by ioquatix (Samuel Williams).

8 messages 2023/04/18

[#113303] [Ruby master Feature#19610] GC.delay_promotion — "peterzhu2118 (Peter Zhu) via ruby-core" <ruby-core@...>

Issue #19610 has been reported by peterzhu2118 (Peter Zhu).

9 messages 2023/04/20

[#113313] [Ruby master Bug#19613] Add version information to all function documentation — "fulldecent (William Entriken) via ruby-core" <ruby-core@...>

Issue #19613 has been reported by fulldecent (William Entriken).

7 messages 2023/04/23

[#113342] [Ruby master Feature#19617] Add Method#binding and UnboundMethod#binding, similar to Proc#binding — "nevans (Nicholas Evans) via ruby-core" <ruby-core@...>

Issue #19617 has been reported by nevans (Nicholas Evans).

9 messages 2023/04/25

[#113381] [Ruby master Bug#19624] Backticks - IO object leakage — pineman via ruby-core <ruby-core@...>

Issue #19624 has been reported by pineman (Jo=E3o Pinheiro).

10 messages 2023/04/30

[ruby-core:113248] [Ruby master Feature#19560] IO#close_on_fork= and IO#close_on_fork?

From: "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Date: 2023-04-14 07:55:57 UTC
List: ruby-core #113248
Issue #19560 has been updated by byroot (Jean Boussier).


> One of the purposes of O_CLOFORK seems to be to avoid thread race condition

Yes, but that's not the reason I want it for Ruby. Agreed that it would be nice to solve both problems though.

> So the API IO#close_on_fork= is inappropriate for the purpose.


Based on the discussion log, it seems that the intent I described here was missed. My goal here isn't to protect from race condition caused by threads forking, but to get an automatic close of some IOs in normal conditions (no race condition).


> It would be difficult to set O_CLOFORK by default

Yes, it shouldn't be set by default.

>  approved to define the constants provided by the OS: O_CLOFORK as File::Constants::CLOFORK, and FD_CLOFORK as Fcntl::FD_CLOFORK.

Thanks, I'll implement that at least, and I'll see about how to create IOs with that option enabled to allow for an emulation layer.

----------------------------------------
Feature #19560: IO#close_on_fork= and IO#close_on_fork?
https://bugs.ruby-lang.org/issues/19560#change-102803

* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
----------------------------------------
### Context

Forking setups are extremely common in the Ruby ecosystem, as they remain the primary way to get parallelism with MRI.

Generally speaking it works very well, however there are two main issues library authors and application owners need to be careful of:

  - Restarting threads
  - Closing inherited connections and other file descriptors.

I believe we could make the second one much easier.

### O_CLOFORK

A couple years ago, [a new flag was added to the POSIX spec: `O_CLOFORK`](https://austingroupbugs.net/view.php?id=1318). Similar to `O_CLOEXEC`, this file descriptor flag make it so the file descriptor is automatically closed upon forking.

Unfortunately its support is relatively limited for now. It's supported on macOS and some relatively exotic unixes, but not in Linux nor most BSDs.

[The feature was discussed on Linux mailing list](https://lore.kernel.org/lkml/20200525081626.GA16796@amd/T/#m5b8b20ea6e4ac1eb3bc5353c150ff97b8053b727), but it seem to have encountered some strong opposition, so it's unclear if we can hope for it to be added.


That said, I don't think it would be too hard for Ruby to shim this feature by closing all IOs with `close_on_fork?` right after fork.

### Ruby shim

This can be implemented as a Ruby shim starting in Ruby 3.1 using the `Process._fork` callback

```ruby
class IO
  def close_on_fork=(enabled)
    if enabled
      ::CloseIOOnFork::IOS[self] = true
    end
    @close_on_fork = enabled
  end

  def close_on_fork?
    @close_on_fork
  end
end

module CloseIOOnFork
  IOS = ObjectSpace::WeakMap.new

  def _fork
    pid = super
    if pid == 0 # child
      ::CloseIOOnFork::IOS.each_key do |io|
        io.close if io.close_on_fork?
      end
    end
    pid
  end
end
Process.singleton_class.prepend(CloseIOOnFork)

rd, rw = IO.pipe
rw.close_on_fork = true
pid = fork do
  p rw.closed? # => true
end
Process.wait(pid)
```

### Usage

With such feature, many network client would mostly just need to set this flag on their sockets, and just properly handle unexpectedly closed connections, which most already do.





-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- [email protected]
 To unsubscribe send an email to [email protected]
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

In This Thread