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=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 0EBDF1F4B4 for ; Thu, 22 Oct 2020 14:15:16 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C179C120B5A; Thu, 22 Oct 2020 23:14:35 +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 841E8120902 for ; Thu, 22 Oct 2020 23:14:33 +0900 (JST) Received: by filterdrecv-p3mdw1-7975856966-wvf77 with SMTP id filterdrecv-p3mdw1-7975856966-wvf77-20-5F9193E9-1F 2020-10-22 14:15:05.18982601 +0000 UTC m=+72673.570364866 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-3 (SG) with ESMTP id m1FAhs-zQbGoKt8kLQp2zQ for ; Thu, 22 Oct 2020 14:15:05.120 +0000 (UTC) Date: Thu, 22 Oct 2020 14:15:05 +0000 (UTC) From: daniel@dan42.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76373 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 15661 X-Redmine-Issue-Author: headius X-Redmine-Sender: Dan0042 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?8sy4RigFvRTdBfCVJrT9zb2J88PC92TMQwdNgaWYaq7kJwBY+ZB11OfHw+l6R4?= =?us-ascii?Q?0owZ5kT5cJW57=2FBa56dQIMGFWL=2FFQFf2tot3OCt?= =?us-ascii?Q?7eXERZVLIQbaFOjhFw2z9ccCQak7v8U6f+g0wg1?= =?us-ascii?Q?Sb5BYUTXbIyzPgw3dBMXwBdfipQOLMMrfiMCyPx?= =?us-ascii?Q?OLXZ7x54Ni21pYi=2FzP=2FUWjXEwilBc4=2FQo8aWhy7?= =?us-ascii?Q?CkSE59gZAUsoNQzoM=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100503 Subject: [ruby-core:100503] [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 Dan0042 (Daniel DeLorme). >From the bug report, I got the idea this was about preventing a chdir while a chdir with block was active _in another thread_. That sounds fine to me, but this code also triggers a warning: ```ruby Dir.chdir("/usr") do #do things in /usr Dir.chdir("local") #warning: conflicting chdir during another chdir block #do things in /usr/local until the end of the block end ``` If we're talking about turning this as well into an error I'm not sure I agree. ---------------------------------------- Bug #15661: Disallow concurrent Dir.chdir with block https://bugs.ruby-lang.org/issues/15661#change-88123 * Author: headius (Charles Nutter) * Status: Closed * Priority: Normal * 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/