From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 1F0CF3858C52 for ; Tue, 13 Feb 2024 15:04:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F0CF3858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1F0CF3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707836668; cv=none; b=HnIH8mqs7rEeVIoULAF0sqpVJBkblTzQgGWyS4ZX4S+nb2Ak4P81JRGXunFLluT4Sj/ToabNIA03ybRLXTGhTWtkcM6rMWF/zhvkAL2RoANl/TR5FYAhCDsWx7PCFROf1HZIRo3BLr7W0vfiV15fflVOPI2WpfRjAd1E2Zmr5ho= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707836668; c=relaxed/simple; bh=xzXX+a9yiYAng787zw3BLdbA1TV9QVjhbbM5NjfsUts=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=RodrC8aQgXZXBubfVnHZwR1Qx2HAkgVhlMu91B7+qtnWwtj12P00Te5mZEjsvDC+ziOPrSJmjv6oMXTLf9803bs56dkeFDcWEuE1UbKuJfDLs045EG06OJg8QJhbranJdxwNvVrOQUvcxMIOikqeX1I7C6qv3AJKTeBlT7fvYSs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id F40A721AFD; Tue, 13 Feb 2024 15:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707836663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5tcXZSNoSJC1h8z+8o0kxsi7PdeNrXh8tVMAhrkVF0=; b=G8RasRaJgbjMQ/6DkCnB1N3YZOEEaWmtKvzvt/I+1dEoOS7pCkJRCjplO4UA4ku1VZzo+0 snKlJ8ooYBSSSIYM7QMWyludyL8EaLnFgaKXsbtPfcVPSo7VJdG1weernP4f/GNPoN8BWd C/lNp3N5r7zG3/RPQhCEP7uadB/+m0U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707836663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5tcXZSNoSJC1h8z+8o0kxsi7PdeNrXh8tVMAhrkVF0=; b=h9LTFbiX6X7GISE8oq8t05R6sy/UDWjpy6V5IClBg1ID6GHiafyeRWddNTPtWcHLAfGxJA +SqHy2n/h2Y5aBCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707836663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5tcXZSNoSJC1h8z+8o0kxsi7PdeNrXh8tVMAhrkVF0=; b=G8RasRaJgbjMQ/6DkCnB1N3YZOEEaWmtKvzvt/I+1dEoOS7pCkJRCjplO4UA4ku1VZzo+0 snKlJ8ooYBSSSIYM7QMWyludyL8EaLnFgaKXsbtPfcVPSo7VJdG1weernP4f/GNPoN8BWd C/lNp3N5r7zG3/RPQhCEP7uadB/+m0U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707836663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5tcXZSNoSJC1h8z+8o0kxsi7PdeNrXh8tVMAhrkVF0=; b=h9LTFbiX6X7GISE8oq8t05R6sy/UDWjpy6V5IClBg1ID6GHiafyeRWddNTPtWcHLAfGxJA +SqHy2n/h2Y5aBCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DC25613404; Tue, 13 Feb 2024 15:04:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MARaNPaEy2X4NQAAD6G6ig (envelope-from ); Tue, 13 Feb 2024 15:04:22 +0000 Message-ID: <0abb6b1d-52ce-43c5-ac49-fa98ad06a810@suse.de> Date: Tue, 13 Feb 2024 16:04:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 1/3] [gdb/dap] Fix exit race Content-Language: en-US To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20240207090224.27521-1-tdevries@suse.de> <20240207090224.27521-2-tdevries@suse.de> <875xz0clgw.fsf@tromey.com> From: Tom de Vries In-Reply-To: <875xz0clgw.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Level: Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=G8RasRaJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=h9LTFbiX X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.50 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; RCPT_COUNT_TWO(0.00)[2]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,sourceware.org:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Score: -4.50 X-Rspamd-Queue-Id: F40A721AFD X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 2/7/24 17:01, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > > Tom> Then I tried to simply remove send_gdb("quit"), and that worked as well, and > Tom> caused no regressions. So, either this is the easiest way to address this, or > Tom> we need to add a test-case that regresses when we remove it. > > Right now main_loop does: > > # Got the terminate request. This is handled by the > # JSON-writing thread, so that we can ensure that all > # responses are flushed to the client before exiting. > self.write_queue.put(None) > > Like the comment says, this approach tries to ensure that all responses > have been flushed to the client before quitting. However, I suppose > this approach does not really work, because main_loop then proceeds to > return. > > One way to fix this would be to have start_json_writer return the thread > object, and then have main_loop join the thread to terminate after > writing the None. This would mean making this particular thread > non-daemon though. > And as I understand it, the downside of that is that it could possibly hang the gdb process. Btw, I think I found a simpler way of achieving this: ... diff --git a/gdb/python/lib/gdb/dap/io.py b/gdb/python/lib/gdb/dap/io.py index 5149edae977..491cf208ae3 100644 --- a/gdb/python/lib/gdb/dap/io.py +++ b/gdb/python/lib/gdb/dap/io.py @@ -65,10 +65,7 @@ def start_json_writer(stream, queue): while True: obj = queue.get() if obj is None: - # This is an exit request. The stream is already - # flushed, so all that's left to do is request an - # exit. - send_gdb("quit") + queue.task_done() break obj["seq"] = seq seq = seq + 1 @@ -79,5 +76,6 @@ def start_json_writer(stream, queue): stream.write(header_bytes) stream.write(body_bytes) stream.flush() + queue.task_done() start_thread("JSON writer", _json_writer) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 7cc5a4681ee..ca4465ff207 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -229,6 +229,8 @@ class Server: # JSON-writing thread, so that we can ensure that all # responses are flushed to the client before exiting. self.write_queue.put(None) + self.write_queue.join() + send_gdb("quit") @in_dap_thread def send_event_later(self, event, body=None): ... Regardless, this doesn't address the root cause of the problem, the race and crash remain. +> In this setup, removing the "quit" here is the right thing to do. I've submitted an updated version (commit message is updated, code is the same) of the patch here ( https://sourceware.org/pipermail/gdb-patches/2024-February/206567.html ). Thanks, - Tom