From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,URIBL_SBL_A autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [IPv6:2a01:4f8:1c0c:6b10::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A3CE91F44D for ; Fri, 26 Apr 2024 10:06:20 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=W/X6JUi1; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=ZX+ojHhE; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 48D7E84503; Fri, 26 Apr 2024 10:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1714125972; bh=MDC87rS+pnGoSpU7yeG/f/10SN7M8e9jQ3CGDAK18TI=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=W/X6JUi1do4hM9ERmE/1oKPwBp7EBS9JigKTkgivLKfXqr0uvXNwc5v2oHOSrTgNz waYP4XjNkTAH44cwjF8uBQIWM0g+1+Y8ioa3S0ZmdBZepqhcRPU6nBfRSe5GSXEflI j+H7KiFZtA1yHCkbUCPVCwGOyqM8OlzYgP1cGkLE= Received: from s.wfbtzhsw.outbound-mail.sendgrid.net (s.wfbtzhsw.outbound-mail.sendgrid.net [159.183.224.105]) by nue.mailmanlists.eu (Postfix) with ESMTPS id C4163844EB for ; Fri, 26 Apr 2024 10:06:08 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=ZX+ojHhE; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=QDj4TfckBb6NvigETI5WyQb4rOYMARcaVKHvL8scyjM=; b=ZX+ojHhEhdPBIZGefp7oFV4MWStnN+EEOycx+31bdqDp7eX/Xu247t0TCzYe3EJfMbam 0FnnVwA+Gt3bcfP7J0tBFr9cjwzZVsq2r5LLdtmotFCvg+kQipkUCO8jMqdP8r8da834y6 TTuLQ6nBCkb/jnmct5A5eNhJxyMGpb37GJ+aRLG4uXjUmdgudC5Q7DUcN4Mn/fokVm0nlf WXOgTbechbe343KkNqIq2b/eoFrv4jpzqDPOXWiZiu5AwnjWs7T+WEqrPSzuR/769ggqV4 6oci0QZcVZ7aTCt+VcO1kFcemzRzgFZ4ETy6YJ+QVdcGE7uNkbAQrJ2fU/RSwVJw== Received: by recvd-547d99795c-z5rnk with SMTP id recvd-547d99795c-z5rnk-1-662B7C8F-3C 2024-04-26 10:06:07.914162208 +0000 UTC m=+1166727.903577190 Received: from herokuapp.com (unknown) by geopod-ismtpd-10 (SG) with ESMTP id NpUxHrCcRLuiwLgvUzYMzQ for ; Fri, 26 Apr 2024 10:06:07.852 +0000 (UTC) Date: Fri, 26 Apr 2024 10:06:07 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20456 X-Redmine-Issue-Author: blowfishpro X-Redmine-Issue-Priority: Normal X-Redmine-Sender: byroot 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-Redmine-MailingListIntegration-Message-Ids: 94321 X-SG-EID: =?us-ascii?Q?u001=2EKmNZ1u3n1vIpO8NNTdp+Q9c0ai7potxbEDLMO7SOJO=2F4KkRUz0d23466m?= =?us-ascii?Q?naiq=2F5fmA4hb60MdRMUAwHZnjIWVFu=2FrqiBOz5c?= =?us-ascii?Q?nOvkBudsSTi7isG5yUq8=2FYeI3wsK8ZpNQ9sXfek?= =?us-ascii?Q?SxInaVAGjsA2LCtCo1fPW8A+xze8g6p1Hiys7qE?= =?us-ascii?Q?w1rOLk8Uc6RM9pZXGqF+Z5lPF+rpGfuYi7ORQtD?= =?us-ascii?Q?fDyoqmlccm=2FLYsD0OauOGjpMpHrnQIvs2shAQQ9?= =?us-ascii?Q?qpaLw=2FE0lGSIA6=2FLLg2LHmNpng=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: YKCG37YSGWPZLCTZZSR6QFDR7BRKK5FX X-Message-ID-Hash: YKCG37YSGWPZLCTZZSR6QFDR7BRKK5FX X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:117725] [Ruby master Bug#20456] Hash can get stuck marked as iterating through process forking List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "byroot (Jean Boussier) via ruby-core" Cc: "byroot (Jean Boussier)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20456 has been updated by byroot (Jean Boussier). > I think we should remove [auto unlock of mutexes owned by dead thread] I very strongly oppose that. ---------------------------------------- Bug #20456: Hash can get stuck marked as iterating through process forking https://bugs.ruby-lang.org/issues/20456#change-108133 * Author: blowfishpro (Talia Wong) * Status: Open * ruby -v: 3.3.0 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- # Steps to Reproduce 1. Iterate over a hash 1. While that iteration is happening, fork the process a. This should be done in a way that causes the iteration to never finish from the child process's view, e.g. fork with a block, or iteration is happening in a different thread than fork 1. Attempt to add a new key to the hash in the child process a. This can be before or after the iteration finishes in the parent process, doesn't matter # Observed Behavior The child process can never add a new key to the hash, always fails with `RuntimeError: can't add a new key into hash during iteration` # Desired The hash is no longer iterating in the child process, so it can be modified as needed # Examples ## With threads: ```ruby h = { a: 1 } t = Thread.new do sleep 0.05 pid = fork do sleep 0.1 puts 'child: before' h[:b] = 2 puts 'child: after' end Process.wait2(pid) end puts 'parent: before' h.each do sleep 0.1 end puts 'parent: after' puts t.join.value.inspect ``` produces: ``` parent: before parent: after child: before can't add a new key into hash during iteration (RuntimeError) [34450, #] ``` ## Without threads: ``` ruby h = { a: 1 } pid = nil puts 'parent: before' h.each do pid = fork do sleep 0.05 puts 'child: before' h[:b] = 2 puts 'child: after' end end puts 'parent: after' puts Process.wait2(pid).inspect ``` produces: ``` parent: before parent: after child: before can't add a new key into hash during iteration (RuntimeError) [17809, #] ``` # Platform information This behavior has been observed in the following environments - Ruby 3.3.0 on Mac OS 14.4.1 (Apple M1 Max) installed via [asdf](https://asdf-vm.com/) - Ruby 2.7.5 on Mac OS 14.4.1 (Apple M1 Max) installed via [asdf](https://asdf-vm.com/) - Ruby 3.2.3 on RockyLinux 8.4 (x86_64) installed from [Fullstaq](https://fullstaqruby.org/) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/