From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 341661F4B4 for ; Mon, 28 Dec 2020 11:58:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C6205120AEB; Mon, 28 Dec 2020 20:58:06 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id D5D66120ADC for ; Mon, 28 Dec 2020 20:58:03 +0900 (JST) Received: by filterdrecv-p3las1-685fdc5bbc-qsvm8 with SMTP id filterdrecv-p3las1-685fdc5bbc-qsvm8-20-5FE9C878-2B 2020-12-28 11:58:48.886740475 +0000 UTC m=+1515393.412268473 Received: from herokuapp.com (unknown) by ismtpd0015p1iad2.sendgrid.net (SG) with ESMTP id RdGsuJmKR8SBnrQ9183KGA for ; Mon, 28 Dec 2020 11:58:48.780 +0000 (UTC) Date: Mon, 28 Dec 2020 11:58:48 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 77677 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17420 X-Redmine-Issue-Author: Eregon X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: Eregon X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr0yJrx5bSF3Teu0FY6WAu?= =?us-ascii?Q?WgAW=2Fqj6Whws7X5ujQHiQWQOEerhBGOU7bMGFfV?= =?us-ascii?Q?5NlWVr7TYEg2Wpb1ufQCdwDRh+LpsqF+Fg2CPuK?= =?us-ascii?Q?ZGm1u1SwHU3=2FLvmlCxyYSUwx8usiBzYr3BsTuXy?= =?us-ascii?Q?1=2FyFMkJY3x0b5FKeLiIvpmNwdqaWqCLuEbZ=2FiQj?= =?us-ascii?Q?NCgCl=2FQVAMmJZgCoU=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 101775 Subject: [ruby-core:101775] [Ruby master Bug#17420] Unsafe mutation of $" when doing non-RubyGems require in Ractor X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17420 has been updated by Eregon (Benoit Daloze). That sounds like a good way to fix it. marcandre (Marc-Andre Lafortune) wrote in #note-3: > the main thread could spin a private thread to do the needed `require`. Whatever code is loaded by require can check `Thread.current`, so it should be a regular Ruby Thread, except the VM or the Ractor impl would create it. ---------------------------------------- Bug #17420: Unsafe mutation of $" when doing non-RubyGems require in Ractor https://bugs.ruby-lang.org/issues/17420#change-89603 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) * ruby -v: ruby 3.0.0dev (2020-12-16T10:12:48Z master a9a7f4d8b8) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- With an empty file `a.rb`: ``` $ ruby --disable-gems -e 'Ractor.new { puts $" }.take' -e:1:in `block in
': can not access global variables $" from non-main Ractors (RuntimeError) ``` That is expected, given the rules for global variables. ``` ruby --disable-gems -e 'Ractor.new { require "./a.rb"; }.take; p $"' [... , "/home/eregon/a.rb"] ``` Is it OK that the Ractor can do `require`, which does modify `$"`? I think it's not, and it might lead to segfaults if e.g. the main Ractor mutates `$"` in parallel to some other Ractor doing `require`. Probably `require` needs to be forbidden in non-main Ractors (it does mutate `$"`, so it's logical), or there needs to be always VM-global synchronization on any access to `$"` (otherwise, segfaults are possible). The latter doesn't seem reasonable, especially when considering the user might do `$".each { ... }`. --- Note that RubyGems' `require` does not work on non-main Ractors (pretty much expected given it depends on a lot of global state): ``` $ ruby -e 'Ractor.new { require "./a.rb"; }.take' :37:in `require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (NameError) ``` This probably also has consequences for `autoload`. Maybe the `zeitwerk` gem can help with the mode to resolve all autoload at once. -- https://bugs.ruby-lang.org/