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=0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 9681D1F44D for ; Mon, 4 Mar 2024 17:38:59 +0000 (UTC) Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 3E38A7F00F; Mon, 4 Mar 2024 17:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1709573931; bh=MoBpAQJsy20k8N+T3KduKAxzYoRyfOKIpHFThtwt06s=; 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=Pfy9dK7p83BQo+0TAt2GyQlbhaxcsmkJbdYYy55kR4KlubkSJzHx2JGHA7tYB7Y46 tqr8+LtVp4ZBsDMWVCxQZtVYGsnJmYtBSCmU6VEIw2tNSRjRjwhYhtyLszQqrqeK/S fAU5P/zfyaJ4qzIf8YIDhTcaLNQLT/jvCzJtmf/8= 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 E933C7EF96 for ; Mon, 4 Mar 2024 17:38:46 +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=jxeRkbyu; 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=5EHSN3R+qDbA5RNZJ4NZ+7WTa7IMI9cjoj9IXLnJg00=; b=jxeRkbyuczu8sVeB+4v0nWQoCpMmh3VprDFPYrKwnwUNp2dx9VA0k/FDVAns/2Lz73+6 w5I06tamQmyEDsiS3h/v18Hcc/zvMJK0mznFt7rapxUK9DnWVuTSEI/PW2VCHEY0wuCjsg 4zFk385SBuhwtPJPUmt6srhYXdAFJ9PD9FOEmAGKl+xroVtT8CDOk4h1H9cj7z6Zrw12Vd jfl6NNsGBttzu/PezSyxkSymVND1dbQDmtaurD7UlYcMbrydPKOScconDLKUeYr2oMHFCM cECZGH3WxfSYJTEus+D2qwbrEQ5WJ+FzS+G4U6alIDg5cOW77sp1GjKvlzB11ovw== Received: by recvd-67cf556c4d-mpwq6 with SMTP id recvd-67cf556c4d-mpwq6-1-65E60725-18 2024-03-04 17:38:45.613684698 +0000 UTC m=+416928.250874260 Received: from herokuapp.com (unknown) by geopod-ismtpd-20 (SG) with ESMTP id EdMKINJkQU6MyrB30UmOQQ for ; Mon, 04 Mar 2024 17:38:45.581 +0000 (UTC) Date: Mon, 04 Mar 2024 17:38:45 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20314 X-Redmine-Issue-Author: mame X-Redmine-Issue-Priority: Normal X-Redmine-Sender: jeremyevans0 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: 93619 X-SG-EID: =?us-ascii?Q?zy3UxWTRryXcrjCh7SV39ZkShJ1PHkEOmoUEekBgd8G8RAJk=2FsUOlbLwuWEoNU?= =?us-ascii?Q?BxG3BBFmcsr21OPpQwa7zNRSwswJm1szgMd841w?= =?us-ascii?Q?HPqc4MXZY8fjkHnsJIjjIMadbLXD4hOOITpqB4M?= =?us-ascii?Q?auo3J8mtURWEB0hoaLH9jauNHDo7yYzc1Q2Prvl?= =?us-ascii?Q?a4B7gMeNSqtttPBX1DX34=2FNxuTERXwJdrjhiO8p?= =?us-ascii?Q?ROwRQ=2FfLz8JDKb7vjZMLxB=2FEOtl6Ujc5krDeWcy?= =?us-ascii?Q?=2FQ9bDL3Y7s=2FeomF1i3F=2FA=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: YQIO2PRHZYPE26SEIXCE6RV5FOQWAHL2 X-Message-ID-Hash: YQIO2PRHZYPE26SEIXCE6RV5FOQWAHL2 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:117053] [Ruby master Bug#20314] Simultaneous Timeout expires may raise an exception after the block List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "jeremyevans0 (Jeremy Evans) via ruby-core" Cc: "jeremyevans0 (Jeremy Evans)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20314 has been updated by jeremyevans0 (Jeremy Evans). Solution 2 makes the most sense to me. If inside a `Timeout.timeout` block, you are swallowing the exception that you provided in the `Timeout.timeout` method call, that to me indicates you do not want to handle it as a timeout. ---------------------------------------- Bug #20314: Simultaneous Timeout expires may raise an exception after the block https://bugs.ruby-lang.org/issues/20314#change-107127 * Author: mame (Yusuke Endoh) * Status: Open * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Launchable reports `TestTimeout#test_nested_timeout` as a flaky test, and I reproduced it as follows. ```ruby require "timeout" class A < Exception end class B < Exception end begin Timeout.timeout(0.1, A) do Timeout.timeout(0.1, B) do nil while true end end rescue A, B p $! #=> # # Exception B is raised after the above call returns #=> test.rb:16:in `p': execution expired (B) p :end # not reach end ``` This is because the timer thread performs two consecutive `Thread#raise` to the target thread. I have discussed this with @ko1 and have come up with three solutions. ### Solution 1 When multiple nested Timeouts expire simultaneously, raise an exception for the outer-most Timeout and let the inner Timeouts expire without throwing an exception. In the above example, it would only raise A. The problem with this approach is that if you are rescuing A in the inner block, it may never ends: ```ruby Timeout.timeout(0.1, A) do Timeout.timeout(0.1, B) do begin sleep rescue A sleep # The exception A is caught. The inner Timeout is already expired, so the code (may) never end. end end end ``` Note that, if A and B did not occur at the same time, it would raise B. This is a race condition. ### Solution 2 When multiple nested Timeouts expire simultaneously, raise an exception for the inner-most Timeout and let the outer Timeouts wait until the inner-most Timeout returns. In the above example, it would raise either A or B, not both. The problem with this approach is that if you are rescuing B in the inner block, it never ends: ```ruby Timeout.timeout(0.1, A) do Timeout.timeout(0.1, B) do begin sleep rescue B sleep # The outer Timeout waits for the inner timeout, and the inner Timeout never return. So this code never ends. end end end ``` ### Solution 3 Make thread interrupt queue one length. If the target thread has already been `Thread#raise(A)`, the new `Thread#raise(B)` blocks until the target thread processes A. Since there will be no more simultaneous Thread#raise, there will be no more exceptions after the end of the block. The timeout timer thread should be changed in consideration that `Thread#raise` may block. -- 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/