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 [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 A8DAF1F44D for ; Sun, 7 Apr 2024 14:23:18 +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=R9vtN/G+; 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=WHrCFhyw; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 3942481436; Sun, 7 Apr 2024 14:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1712499791; bh=cwa7xLIpJJT4Lq1xHDBs7SRgEOfmC1Gdap5l1HHS/t0=; 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=R9vtN/G+tDLyp7cD3wI0j6WJ/YmymV/JfW+0TboP3QnIDyxQk5nmG5T4Vj4/H5NL5 q7DJYF+ymVNVSIJzbrpmE645Aux9fLv3uJhpWCQsFK3o6gT6S7XVeFXlALwnu1FrVv lTM/XSxTzR/MsqDgQZOEHwTPKZ5PYreVXpVDCsBQ= Received: from s.wrqvtvvn.outbound-mail.sendgrid.net (s.wrqvtvvn.outbound-mail.sendgrid.net [149.72.120.130]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 237E881430 for ; Sun, 7 Apr 2024 14:23: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=WHrCFhyw; 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=YYTrb1SuNVxBaur15+DasZHLFQNAzp2znLtNTKCEbok=; b=WHrCFhywfAAigM2Gl25dloDTGDbpA1fI1Gp0L/k5u4CMihzj5odyHKQSPGeQ38edUC3R s5AA3XkTROp6Ro2orcvw/boUYUTwK9OzT0VNnwssGGOFzFqMEtoulCC4HiZ7XNWL/WeAWT c3ZZoerBMrf/7RGeDhL5yMRHUQsSEQFOwyJ+eHuCsetIq2ZtyyTmdzv4MOmxgZqBMIzNON sOqxRmzRVMb+EtZrnXSVv251G2iix5p0z0viuIzRwN9gkIIG9xj1Z2N9aWwNFDIbUj+/t9 zTLlPNiDMQg54rIDvRAOYXXnomajiRdY8JQ+GJEiUbe5yWB/hGrcgKkCV8870t0g== Received: by recvd-75c664ffc8-x27pj with SMTP id recvd-75c664ffc8-x27pj-1-6612AC4A-9 2024-04-07 14:23:06.714046403 +0000 UTC m=+1704229.791663597 Received: from herokuapp.com (unknown) by geopod-ismtpd-8 (SG) with ESMTP id 2KfNm6nBQI2GqO5FQDksLA for ; Sun, 07 Apr 2024 14:23:06.667 +0000 (UTC) Date: Sun, 07 Apr 2024 14:23:06 +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: 94054 X-SG-EID: =?us-ascii?Q?u001=2E3QFJPY5gaRwyNXkncYONHM3OeFnb=2FgeOrLDgg3PYIKrq5rvk81iAipQ1q?= =?us-ascii?Q?cdmuT9o5PIWGjXtTDstodNmslT=2F6xfCuIofWR2K?= =?us-ascii?Q?w8msDgVaVLyGBkOvs5+v5QclX55wHUOA4Dku+8V?= =?us-ascii?Q?9uYtHPUMCKMa=2FFsRhiXxpM=2FYTXhlkDoVcl9SHAu?= =?us-ascii?Q?UQddH2BnDPGrURTEDCdQ6wmXMownFcEUZ=2F74OF0?= =?us-ascii?Q?2siU9NCginPABLYGBA1li30HTC7x0PS+Mx6hDmz?= =?us-ascii?Q?eOVS=2FrLb7joGQKT57QQE18q0Ag=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: 2JKI5MFNLGEAXPU4UROYYBZLZBB7SPJE X-Message-ID-Hash: 2JKI5MFNLGEAXPU4UROYYBZLZBB7SPJE 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:117459] [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). Proposed change: https://github.com/ruby/ruby/pull/10482 ---------------------------------------- Bug #20414: `Fiber#raise` should recurse to `resumed_fiber` rather than failing. https://bugs.ruby-lang.org/issues/20414#change-107843 * 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/