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=-4.1 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham 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 E5D5E1F4B4 for ; Thu, 24 Dec 2020 04:50:58 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A5318120B49; Thu, 24 Dec 2020 13:50:07 +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 DFA64120B48 for ; Thu, 24 Dec 2020 13:50:05 +0900 (JST) Received: by filterdrecv-p3mdw1-7474cd8bfd-htsvt with SMTP id filterdrecv-p3mdw1-7474cd8bfd-htsvt-17-5FE41E27-D 2020-12-24 04:50:47.409914402 +0000 UTC m=+1144112.729124703 Received: from herokuapp.com (unknown) by geopod-ismtpd-6-3 (SG) with ESMTP id 2Bja7LBDS9-srlSGiz0wPw for ; Thu, 24 Dec 2020 04:50:47.330 +0000 (UTC) Date: Thu, 24 Dec 2020 04:50:47 +0000 (UTC) From: mame@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 77574 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 15661 X-Redmine-Issue-Author: headius X-Redmine-Sender: mame 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?EJh2gqwnyqXtd++xo=2FinyA1V0bXouTB4FkWnzNiKb48iE3Lt0SAOs6VZym2J1T?= =?us-ascii?Q?RJzgBICR6Qvza9qTABoPuVpCIacDs9XCpZPoDnZ?= =?us-ascii?Q?0pjjComYHmbcPERNSG4np+AfqaTJ9rjmo9E7i4Y?= =?us-ascii?Q?tT6sFBCNw19hY0kCuMM13YK1M8WxlkzXebu=2F9Fq?= =?us-ascii?Q?z69rsm54=2F+63FtDlqn037vgVYvdsbJUtXo9CwEf?= =?us-ascii?Q?3n=2F8j2ld+Tm0ynIi0=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 101671 Subject: [ruby-core:101671] [Ruby master Bug#15661] Disallow concurrent Dir.chdir with block 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 #15661 has been updated by mame (Yusuke Endoh). This issue was discussed at the last dev-meeting. https://github.com/ruby/dev-meeting-log/blob/master/DevelopersMeeting20201210Japan.md#bug-15661-disallow-concurrent-dirchdir-with-block-jonathanhefner > * ko1: How about raising an exception if different thread calls Dir.chdir, and showing a warning if the same thread calls Dir.chdir > * When Thread A is running Dir.chdir("aaa") do ... end > * Thread B attempts to run Dir.chdir("bbb") #=> an exception > * Thread B attempts to run Dir.chdir("bbb") { ... } #=> an exception > * Thread A attempts to run Dir.chdir("bbb") #=> a warning > * Thread A attempts to run Dir.chdir("bbb") { ... } #=> no warning > > Conclusion: > * matz: go ahead I've created a PR: https://github.com/ruby/ruby/pull/3990 I will merge it if it passes the test suite. ---------------------------------------- Bug #15661: Disallow concurrent Dir.chdir with block https://bugs.ruby-lang.org/issues/15661#change-89491 * Author: headius (Charles Nutter) * Status: Open * Priority: Normal * Target version: 3.0 * ruby -v: all * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- `Dir.chdir` with a block should disallow concurrent use, since it will almost never produce the results a user expects. In https://bugs.ruby-lang.org/issues/9785 calls for `Dir.chdir` to be made thread-safe were rejected because the underlying native call is process-global. This is reasonable because there's no way to easily make the native chdir be thread-local (at least not without larger changes to CRuby itself). However the block form of `chdir` is explicitly bounded, and clearly indicates that the dir should be changed only for the given block. I believe `Dir.chdir` should prevent multiple threads from attempting to do this bounded `chdir` at the same time. Currently, if two threads attempt to do a `Dir.chdir` with a block, one of them will see a warning: "conflicting chdir during another chdir block". This warning is presumably intended to inform the user that they may see unpredictable results, but I can think of no cases where you would ever see predictable results. In other words, there's no reason to allow a user to do concurrent `Dir.chdir` with a block because they will always be at risk of unpredictable results, and I believe this only leads to hard-to-diagnose bugs. The warning should be a hard error. The warning should also be turned into an error if a non-block `Dir.chdir` call happens while a block Dir.chdir is in operation. The important thing is to protect the integrity of the current directory during the lifetime of that block invocation. In CRuby terms, the patch would be to check for `chdir_blocking > 0` and then simply error out, unless it's happening on the same thread. Concurrent non-block `Dir.chdir` would be unaffected. This only protects the block form from having the current dir change while it is executing. See https://github.com/jruby/jruby/issues/5649 -- https://bugs.ruby-lang.org/