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.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (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 114D71F44D for ; Sun, 7 Apr 2024 14:26:17 +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=aFkTVKXO; 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=nna972x1; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 096A98143B; Sun, 7 Apr 2024 14:26:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1712499970; bh=uKRDc1nhkj7BOmHDYjI9Mh5vk13I5aqDuTAe4yRJcU8=; 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=aFkTVKXOeAR3R0UC4vWQjiM80q8WTt4+oMI+P0jai9wf1zfJCMhkijzSiBk9QDXry /okyCPzVlb6OXQzboj4Xru/ec9ifKGb28oPr1iI8twHOJqLEgQgBdeS7HNPkAWAD9k PfvlRpjinFNkCeH80k95WrkQjpm6CDr/Graw2NRE= Received: from s.wrqvtbkv.outbound-mail.sendgrid.net (s.wrqvtbkv.outbound-mail.sendgrid.net [149.72.123.24]) by nue.mailmanlists.eu (Postfix) with ESMTPS id F322581434 for ; Sun, 7 Apr 2024 14:26:05 +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=nna972x1; 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=4G3MxSYkSNrDVbyKByOornfsu1qPC7SCoBXeT+wiI1I=; b=nna972x1/T8JAlaF43WMPV5BrmyqBI+zV8+X9pqPZkE3x4vLFzbGW4+X3NY7RRVF+f7p Ufdw7oyxqLgWKYR1hESGVvf1Cd1zROp1vrsa1Bk3JfvBqe6Q4/SFiwY1pJrZKYpc6e3436 02Ax9tdlJcb5gWACBLWtfBd00BdSxWzYDoSb0pXYsS1UmWwE9kpGiy+YGvMAac5M7sk8b1 iODxM0KoA8HsWBRppCC8ev4K2jyOBta9/Ud0TxGUypZ+Y4S9YHpu3UDuK6cdS0oJ/pZH7j kT4qpFzmN8Mk0OJH9O/vnhJqjdvXkcIg4YqTC5p2jEq05OlZyE2dHZXRhkw8Nr6Q== Received: by recvd-d64b65bdd-rbqz4 with SMTP id recvd-d64b65bdd-rbqz4-1-6612ACFC-7 2024-04-07 14:26:04.838182098 +0000 UTC m=+231342.329789433 Received: from herokuapp.com (unknown) by geopod-ismtpd-33 (SG) with ESMTP id GNrYaagUTam7vaT3gLJb_w for ; Sun, 07 Apr 2024 14:26:04.779 +0000 (UTC) Date: Sun, 07 Apr 2024 14:26:04 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20414 X-Redmine-Issue-Author: ioquatix X-Redmine-Issue-Assignee: ioquatix X-Redmine-Issue-Priority: Normal X-Redmine-Sender: ioquatix 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: 94056 X-SG-EID: =?us-ascii?Q?u001=2E3QFJPY5gaRwyNXkncYONHM3OeFnb=2FgeOrLDgg3PYIKrq5rvk81iAipQ1q?= =?us-ascii?Q?cdmuT9o5PIWGjXtTDstodNmslT=2F6xfCuIofWR2K?= =?us-ascii?Q?w8msDgVaVLzVNkwYFbokp3cgb3o4e12=2FLa6ZC7r?= =?us-ascii?Q?YsR60K84iS7MR044mhIRWKsmm70P2HM0tmO61uQ?= =?us-ascii?Q?JQ6XoMz53rmIAFD7UYwNTGXKiIWgFsbj8viSapk?= =?us-ascii?Q?CtJmH6a2xDLaCQFM6viUoQXEZ+cZm3teTWfYq+q?= =?us-ascii?Q?n7KmtfFxpXdV8KNZ+jY5BPv3MA=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: GLK77QOLIBEMQKBDK4T5TCTCYSYEJADW X-Message-ID-Hash: GLK77QOLIBEMQKBDK4T5TCTCYSYEJADW 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:117461] [Ruby master Bug#20414] `Fiber#raise` should recurse to `resumed_fiber` rather than failing. List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "ioquatix (Samuel Williams) via ruby-core" Cc: "ioquatix (Samuel Williams)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20414 has been updated by ioquatix (Samuel Williams). With the proposed change, the following program: ```ruby root_fiber = Fiber.current f1 = Fiber.new do puts "f1 enter" root_fiber.transfer puts "f1 exit" ensure puts "f1 ensure" end f2 = Fiber.new do puts "f2 enter" f1.resume puts "f2 exit" ensure puts "f2 ensure" end f2.transfer begin puts "raise" f2.raise(Interrupt) rescue Interrupt => e puts "rescue Interrupt" end ``` ... generates the following output: ``` f2 enter f1 enter raise f1 ensure f2 ensure rescue Interrupt ``` ---------------------------------------- Bug #20414: `Fiber#raise` should recurse to `resumed_fiber` rather than failing. https://bugs.ruby-lang.org/issues/20414#change-107848 * Author: ioquatix (Samuel Williams) * Status: Open * Assignee: ioquatix (Samuel Williams) * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- The following program will fail with `FiberError`, and is difficult to properly clean up: ```ruby root_fiber = Fiber.current f1 = Fiber.new do root_fiber.transfer end f2 = Fiber.new do f1.resume end f2.transfer f2.raise("error") # => `raise': attempt to transfer to a resuming fiber (FiberError) ``` This program deliberately set's up a scenario where `f2` is resuming `f1`. Trying to raise an exception on `f2` is impossible, because the only way control flow can return to it, is when `f1` yields or exits. We can avoid this problem, by raising the exception on f1, and we can do this automatically using the following logic: ```c static VALUE fiber_raise(rb_fiber_t *fiber, VALUE exception) { // Add this recursive step: if (fiber->resuming_fiber) { return fiber_raise(fiber->resuming_fiber, exception); } // Existing code ... else if (FIBER_SUSPENDED_P(fiber) && !fiber->yielding) { return fiber_transfer_kw(fiber, -1, &exception, RB_NO_KEYWORDS); } else { return fiber_resume_kw(fiber, -1, &exception, RB_NO_KEYWORDS); } } ``` This makes `Fiber#raise` much more robust and useful for the purpose of stopping fibers, without knowing exactly what they are doing. -- 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/