From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id E52C13858CDB for ; Thu, 23 Mar 2023 16:04:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E52C13858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 25A31337DB; Thu, 23 Mar 2023 16:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1679587474; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pcPe1vY/n9uyFtn2e8Yt6CoKuPXK+cL/taKUP3R9ymw=; b=PLUBnwFqdjIG3zIn4ooJ0rIM2KL75QxCfbIn64ijb6agDQBLZioef4c08gFiEgjEkCTOYC ugi4il1UjNxmUqoKg/CiP42TLOTf4Sjx/V45SbEcLYumEikwNtTDVg7DhLyjP6C4WhJ7Br JQiwR7zEnIYZ84A8Y5Ikbfcy5sUobiE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1679587474; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pcPe1vY/n9uyFtn2e8Yt6CoKuPXK+cL/taKUP3R9ymw=; b=RJOqifWPZpKS3EhdjDawCPi78yhGfQXQWN8wzXLm3Mq2+ZWJ4TPgpXbUTWGtwBCsVKIGxH DdUF91wyLflf4BBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0FCA213596; Thu, 23 Mar 2023 16:04:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mWuPApJ4HGQrOwAAMHmgww (envelope-from ); Thu, 23 Mar 2023 16:04:34 +0000 Message-ID: Date: Thu, 23 Mar 2023 17:04:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] Fix race in DAP startup To: Tom Tromey , gdb-patches@sourceware.org References: <20230322143418.1914025-1-tromey@adacore.com> Content-Language: en-US From: Tom de Vries In-Reply-To: <20230322143418.1914025-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 3/22/23 15:34, Tom Tromey via Gdb-patches wrote: > Internal AdaCore DAP testing on Windows has had occasional failures > that show: > > assert threading.current_thread() is _dap_thread > > I think this is a race in DAP startup: the _dap_thread global is only > set on return from start_thread, but it seems possible that the thread > itself could already run and encounter a @in_dap_thread decorator. > > This patch fixes the problem by setting the global before running any > of the code in the new thread. This also lets us remove a FIXME. Hi, I tried this patch out, hoping it would fix the stability issues I have with the gdb.dap tests, but I'm still seeing those, so I filed a PR: https://sourceware.org/bugzilla/show_bug.cgi?id=30268 . Thanks, - Tom > --- > gdb/python/lib/gdb/dap/server.py | 4 +--- > gdb/python/lib/gdb/dap/startup.py | 12 +++++++++--- > 2 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py > index 92b4eee1c5e..ff88282049f 100644 > --- a/gdb/python/lib/gdb/dap/server.py > +++ b/gdb/python/lib/gdb/dap/server.py > @@ -100,9 +100,7 @@ class Server: > log("WROTE: <<<" + json.dumps(obj) + ">>>") > self.write_queue.put(obj) > > - # This must be run in the DAP thread, but we can't use > - # @in_dap_thread here because the global isn't set until after > - # this starts running. FIXME. > + @in_dap_thread > def main_loop(self): > """The main loop of the DAP server.""" > # Before looping, start the thread that writes JSON to the > diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py > index 22246a937ce..aa834cdb14c 100644 > --- a/gdb/python/lib/gdb/dap/startup.py > +++ b/gdb/python/lib/gdb/dap/startup.py > @@ -59,14 +59,20 @@ def start_thread(name, target, args=()): > with blocked_signals(): > result = threading.Thread(target=target, args=args, daemon=True) > result.start() > - return result > > > def start_dap(target): > """Start the DAP thread and invoke TARGET there.""" > - global _dap_thread > exec_and_log("set breakpoint pending on") > - _dap_thread = start_thread("DAP", target) > + > + # Functions in this thread contain assertions that check for this > + # global, so we must set it before letting these functions run. > + def really_start_dap(): > + global _dap_thread > + _dap_thread = threading.current_thread() > + target() > + > + start_thread("DAP", really_start_dap) > > > def in_gdb_thread(func):