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 7EC8A1F44D for ; Thu, 29 Feb 2024 09:31:21 +0000 (UTC) Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id A30477EFB3; Thu, 29 Feb 2024 09:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1709199069; bh=UBVcyToILAghlxNs0HAkSTYWbZt/84IWKKPNpnbvE3U=; 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=c3fqlvrIMNyjBbINMlqqbaRq3PaclbADbCZmDAlVuDr0CuzGsTyCQhx0RfsaN/F7A RJuGfaboMfTPwXKoXtlnaG05SugQNpgDF/jFt4TWQ1/5nQ0m0Ld3jcd8juWN1yuT0h Bb0JPofmmj27UBCk7yHBDdO1Cr2ZEqCEq5IHBiug= Received: from s.wrqvwxzv.outbound-mail.sendgrid.net (s.wrqvwxzv.outbound-mail.sendgrid.net [149.72.154.232]) by nue.mailmanlists.eu (Postfix) with ESMTPS id ED68B7EFB0 for ; Thu, 29 Feb 2024 09:31:04 +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=EG4Yu3Qo; 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=LsWi9NOz5TptRJ7rp0Q7addgyvVQD0aTyW0QLbkWJsI=; b=EG4Yu3QoJMyTz5ccOYWBZI0ul5QrktrkkhyPsP1dAvbvdmbylN1nkg8BuLiLW6ttBQKF YVXV/T/cnA5L6tpwZc8VuV4a9qXLjrW8gnBZT5cveAX3zY2AzNgnnRBn6COjVeqe6v5SuC n2be1d4NDLh6h44swn1JPfpMexWbPtOe9c6bzPqPfCBWRI4XN5ee3iitxNqxFoZpG7VTUL IulhLnTKkHuTq+VtoCpzJVTnfJaMdpNOkfPNtaZ3jQ3A7P45mWQ+Tk1VhF2kI38pombboy 1KZ7Njl+h6+Ys9GLKiOgAttRdkJFXM2PCXBfbKYhE9SIEch3SOKQR0cwchEAa95Q== Received: by recvd-6449d6bd6c-kh9rr with SMTP id recvd-6449d6bd6c-kh9rr-1-65E04ED6-A 2024-02-29 09:31:02.730871347 +0000 UTC m=+42084.181177043 Received: from herokuapp.com (unknown) by geopod-ismtpd-27 (SG) with ESMTP id MqhXJwNhQ0G1o7ngcH6zrg for ; Thu, 29 Feb 2024 09:31:02.681 +0000 (UTC) Date: Thu, 29 Feb 2024 09:31:02 +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: Eregon 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: 93569 X-SG-EID: =?us-ascii?Q?DvL3W2Xo+Vk=2FeUn3F50L=2FNc8u9NqZCnbE0mXZHiyye4R1YZg=2FtAFc0SAFzpcS=2F?= =?us-ascii?Q?Zcr7BqPN=2FYCcMZBMITNeIci9STxYay0JAJWPbek?= =?us-ascii?Q?rFR+qXRqy=2FPyzhRcOuFu2gcJz99Vc5B9vpKOmhu?= =?us-ascii?Q?6+Rg3wddIST2R5nZ8raQ2PQMoJSYot0W1mrjiMn?= =?us-ascii?Q?SjnPZF2RC9mqPCKKV=2F5aA4utQz2vnZXQIQQt8=2Fa?= =?us-ascii?Q?BxGAb8DVi5WePNf0yuv6Jsl91k9kBoAAJnLPDdl?= =?us-ascii?Q?wtPb=2Fc8uOGL=2FXSUTT7r4A=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: 6EHZCRD3ZW6VDNY4SE22NLE5IYOZKL3O X-Message-ID-Hash: 6EHZCRD3ZW6VDNY4SE22NLE5IYOZKL3O 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:117010] [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: "Eregon (Benoit Daloze) via ruby-core" Cc: "Eregon (Benoit Daloze)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20314 has been updated by Eregon (Benoit Daloze). I'm not sure how Solution 3 would work. `Thread#raise` would block until what? Until the exception started to be raised/thrown on that thread? I think that would not fix that snippet. It does not seem reasonable to wait until the exception has been rescued (or escapes the thread) because that could run arbitrary code via `ensure` which could take a long time (and block the caller of `Thread#raise` for a long time). I wonder if we should always use `Timeout::ExitException` to "unwind" until we exit the corresponding block given to `Timeout.timeout`. Unsure if that would help for this issue though. Maybe there are other solutions too? Between solutions 1 and 2, 2 seems better because it seems clearly broken code to `rescue B; sleep; end` in `Timeout.timeout(0.1, B)`. In any case `sleep` in `ensure`/`rescue` is broken code as it can already hang (e.g. with a single `Timeout.timeout(0.1, SomeKlass)` around it, or without using Timeout). ---------------------------------------- Bug #20314: Simultaneous Timeout expires may raise an exception after the block https://bugs.ruby-lang.org/issues/20314#change-107071 * 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/