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-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.1 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_PASS 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 886FD20248 for ; Thu, 14 Mar 2019 05:09:45 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 7D4A8121930; Thu, 14 Mar 2019 14:09:42 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id EA0E2121481 for ; Thu, 14 Mar 2019 14:09:39 +0900 (JST) Received: by filter0029p3las1.sendgrid.net with SMTP id filter0029p3las1-24651-5C89E212-14 2019-03-14 05:09:38.793912707 +0000 UTC m=+192728.085054108 Received: from herokuapp.com (unknown [3.80.34.250]) by ismtpd0060p1mdw1.sendgrid.net (SG) with ESMTP id OP4Al2WcQl65cEu3LOaD8Q for ; Thu, 14 Mar 2019 05:09:38.740 +0000 (UTC) Date: Thu, 14 Mar 2019 05:09:38 +0000 (UTC) From: nobu@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 67278 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15661 X-Redmine-Issue-Author: headius X-Redmine-Sender: nobu 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?q8Dly+pU2+3ektTtZVXgZtbJPXwqo7p86jCsvYTW4BxLS6nsUvUT4UGiO4yNtM?= =?us-ascii?Q?JDjdN4uE0rVGFmuXRZFvvbAdKoEaXl3XJCXGY0J?= =?us-ascii?Q?p+Mra6XG9HAFxggXdR1g9dVmS+dAvx8BAi45=2FVZ?= =?us-ascii?Q?zL13CMz3Ui2S6DgeiBg0tTq2TGGBVSyzhK7FNXQ?= =?us-ascii?Q?YJrzP6zmF6XkxTHJMktu1S6StQvhJTEKBGA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 91826 Subject: [ruby-core:91826] [Ruby trunk 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 nobu (Nobuyoshi Nakada). Description updated Why not blocking until another block terminates? ---------------------------------------- Bug #15661: Disallow concurrent Dir.chdir with block https://bugs.ruby-lang.org/issues/15661#change-77096 * Author: headius (Charles Nutter) * Status: Open * Priority: Normal * Assignee: * Target version: * 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/