From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id D836F3858D1E for ; Fri, 23 Feb 2024 17:27:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D836F3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D836F3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708709230; cv=none; b=w1QDSxCIGOL7GAsc00VYgtRadjVYyrKUi16khZP16I7izltvh5t/oYCQyRCmV1gIyNmgsBuRGnFE/4e3miAZREKSGGn+IW29C7urKcCbshdkIUTa/kC8dtzoHNQd40BC/HvF177hlM4i25v9Nu2O2mIGRnKJTVULE2dDpxw5/lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708709230; c=relaxed/simple; bh=zrF/hi88kwzhrwl7zQWGcfB+sj2nANPUQ3wHquF76lI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MiKQHLiLKXN6vfmoMTqudjrsXmKhkLfS03ny7ZDmkGlHj6wlc5GSlXKkiYJJh54wSbV45hyYWixdcKrixjPNtyaDTLyInsrGzt2pppgbx+PmmWasqG0QG4nDRiv5yIEjGZsYGf4yVMH8cRGaHrR4QyDdDRO++kD2Hv7EMd6HC0o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6005a.ext.cloudfilter.net ([10.0.30.201]) by cmsmtp with ESMTPS id dWENr9X3wQr4SdZKFrSG26; Fri, 23 Feb 2024 17:27:07 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id dZKEr3R4v9ERDdZKErvx7b; Fri, 23 Feb 2024 17:27:06 +0000 X-Authority-Analysis: v=2.4 cv=OtpJyT/t c=1 sm=1 tr=0 ts=65d8d56a a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=k7vzHIieQBIA:10 a=Qbun_eYptAEA:10 a=6y1rWbpBaBsHmcG3g0cA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hdCwZsWCHEcrbwtBb1zEmJ5v78ylGvY4C9ednexPOL0=; b=eodApewkpcJGGHD67k+9x6Le3M ZRXj2ax94VXilMh/MXWu1C9MUpht1yiBOMIPgz1XmVQzkQOiyOnKXhkd5L4+AFC0Zlgyr3tg3fGmB MY22N4Mk5K/oL0AJWDQkOp2D0; Received: from 71-211-170-195.hlrn.qwest.net ([71.211.170.195]:35440 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rdZKE-0034fO-0l; Fri, 23 Feb 2024 10:27:06 -0700 From: Tom Tromey To: Tom de Vries Cc: gdb-patches@sourceware.org, Tom Tromey Subject: Re: [PATCH 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel References: <20240223165128.32211-1-tdevries@suse.de> <20240223165128.32211-2-tdevries@suse.de> X-Attribution: Tom Date: Fri, 23 Feb 2024 10:27:05 -0700 In-Reply-To: <20240223165128.32211-2-tdevries@suse.de> (Tom de Vries's message of "Fri, 23 Feb 2024 17:51:28 +0100") Message-ID: <87jzmvxf9y.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.170.195 X-Source-L: No X-Exim-ID: 1rdZKE-0034fO-0l X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-170-195.hlrn.qwest.net (murgatroyd) [71.211.170.195]:35440 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfPtIm3aHvcfwsWmW1P0WrBJsWrOyPk5cfV/avpjqA4vqfYhB7EJAHzVF0/LaqdrMyhsHiFWG3rb3BUyF4WT2ty1ugwDMInJUgPN6Ns9d5vs+voirPUAs iwx6uWC7EFRHQNnXIHj9vdhowlRVJBvBORM2sgPYFDh2F27ZFKxeiAGHEoW4GsyCTFIAsRcAaPCdv1H0QG8P1kTMt5BhapC1dow= X-Spam-Status: No, score=-3016.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >>>>> "Tom" == Tom de Vries writes: Tom> The idea is that this interrupt triggers while in fn here in message (a nested Tom> function of send_gdb_with_response): Tom> ... Tom> def message(): Tom> try: Tom> val = fn() Tom> result_q.put(val) Tom> except (Exception, KeyboardInterrupt) as e: Tom> result_q.put(e) Tom> ... Tom> but instead it triggers outside the try/except. Thanks for the clear explanation. Tom> I left the two "sleep 0.2" in the test-case, I didn't see a reason to remove Tom> those. Those are there to try to make the test actually interrupt the command in question -- removing them would make it more likely to just interrupt the surrounding dispatch machinery, which isn't interesting. Tom> @@ -435,12 +466,19 @@ def send_gdb_with_response(fn): It seems to me that send_gdb also has this issue -- that is, the cancellation could arrive just in time to cause a KeyboardInterrupt. Also I wonder how multi-step / DAP-thread commands like 'continue' are handled. Tom> def message(): Tom> try: Tom> - val = fn() Tom> + if not _server.canceller.enter_interruptable(): Tom> + raise KeyboardInterrupt() Tom> + try: Tom> + val = fn() Tom> + finally: Tom> + _server.canceller.exit_interruptable() This kind of thing is better with a context manager. Tom> send_gdb(message) Tom> + if _server.canceller.is_cancel_pending(): Tom> + result_q.put(KeyboardInterrupt()) Tom> val = result_q.get() I don't understand how this addition has an effect. It seems to me that since a Queue is FIFO, and since the response Queue is only used for a single value, that this addition will just be ignored. FWIW, cancellation is inherently racy. I'm not opposed to trying to make this more reliable but I think it may be pretty hard. Maybe some kind of installable exception handler that is run when post_event fails would be one way. Not sure. Tom