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.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,RDNS_NONE, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (unknown [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) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 17B981F461 for ; Wed, 17 Apr 2024 11:36:45 +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=fqUqChgQ; 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=U+646M8C; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id E781D843E4; Wed, 17 Apr 2024 11:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1713353797; bh=/g7oe+9d1gmva7e1OfMYkAAg794/aqiGszXq/YzHPEg=; 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=fqUqChgQ76rws1V/3svH4SJfrPdMKfNrR75Hw07PM6bNWkg2RJV0MJ6dW/hGqVel/ LTCVhoHhweTn+6WWxXOPIsHCDJoydbwvTuBIoTIKIkFGDFWrW80+mAdoTNT7iWn1+c oT4kOQjoOpIveUg6NVJLGER1RVBbKgIpgwsPFGpI= Received: from s.wrqvtzvf.outbound-mail.sendgrid.net (s.wrqvtzvf.outbound-mail.sendgrid.net [149.72.126.143]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 75021843DF for ; Wed, 17 Apr 2024 11:36:32 +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=U+646M8C; 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=om3rNTzvRbFsIGqj2pEa6UjlJdZaRaiUPH+RU23td3g=; b=U+646M8CNjFXWC6KKBKKE8oP6qpQE6xFkxN0Wk0UeH/e03XbnK/o+V8MXEdbwkZypsfI IN/Y7ormXZRfD043QJedsG7zRuL+3QIbQ6MofoR7UuQeysY3x3TEFYpMeaFv9H929Ra0yC UYaHKy/jxYXTpUa1X1hBGUl1t+BbohAs2c44J+vmRNyhkimeN71Qvmo9XwcKXYpz57DkBH 8wAlPN1FUWFw8flQhPqpyaLkdIgATYmsSoQuNxx9lr4wkcVQjBZjNwZ6tu9k6nFZGhC2uR uAi8TRONvWDhtC8klNtEfMLxRFX7vG0WaBQih001ozRsCsJUSEqM3AyfaFAKeI6g== Received: by filterdrecv-854b845bd5-wjkkx with SMTP id filterdrecv-854b845bd5-wjkkx-1-661FB43F-9 2024-04-17 11:36:31.20415908 +0000 UTC m=+395223.812604456 Received: from herokuapp.com (unknown) by geopod-ismtpd-26 (SG) with ESMTP id ggDOPb3TTjSTqmSvwVmJvQ for ; Wed, 17 Apr 2024 11:36:31.155 +0000 (UTC) Date: Wed, 17 Apr 2024 11:36:31 +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: 94159 X-SG-EID: =?us-ascii?Q?u001=2E3QFJPY5gaRwyNXkncYONHM3OeFnb=2FgeOrLDgg3PYIKrq5rvk81iAipQ1q?= =?us-ascii?Q?cdmuT9o5PIWGjXtTDstodNmslT=2F6xfCuIofWR2K?= =?us-ascii?Q?w8msDgVaVLx7pkTQfe7m3ngCmjGcf8O+7EWU+zA?= =?us-ascii?Q?AtHgoCXAylK5IyYSKyOs4CF7CqCqcOx1OtkXd9E?= =?us-ascii?Q?ZTTNuAdbdRIXmXshCqH5tevo63lZINCY1B3wd+Q?= =?us-ascii?Q?IzsOcIzzpNhWZoCcauf1xzu=2FWykdBEPf=2F9mQ3xx?= =?us-ascii?Q?bUxj8NfnVItBnkp9JpjlQAHotQ=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: YFTYJZ24XMYXLPX3EQ5XHLVTHDDN6C3C X-Message-ID-Hash: YFTYJZ24XMYXLPX3EQ5XHLVTHDDN6C3C 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:117563] [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). Status changed from Open to Closed Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED Merged in . ---------------------------------------- Bug #20414: `Fiber#raise` should recurse to `resumed_fiber` rather than failing. https://bugs.ruby-lang.org/issues/20414#change-107962 * Author: ioquatix (Samuel Williams) * Status: Closed * Assignee: ioquatix (Samuel Williams) * Backport: 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED ---------------------------------------- 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/