public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Tom de Vries <tdevries@suse.de>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel
Date: Wed, 28 Feb 2024 13:12:26 -0700	[thread overview]
Message-ID: <87o7c0tkk5.fsf@tromey.com> (raw)
In-Reply-To: <20240226115825.29705-2-tdevries@suse.de> (Tom de Vries's message of "Mon, 26 Feb 2024 12:58:25 +0100")

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> Fix this by:
Tom> - in CancellationHandler, renaming variable in_flight to in_flight_dap_thread,
Tom>   and adding a variable in_flight_gdb_thread to be able to distinguish when
Tom>   a request is in flight in the dap thread or the gdb thread.
Tom> - adding a wrapper Cancellable to to deal with cancelling the wrapped
Tom>   event
Tom> - using Cancellable in send_gdb and send_gdb_with_response to wrap the posted
Tom>   event
Tom> - in CancellationHandler.cancel, only call gdb.interrupt if
Tom>   req == self.in_flight_gdb_thread.

Thanks.  I like this patch a lot.

I have one question about it.

Tom> +    @contextmanager
Tom> +    def interruptable_region(self, req):
Tom> +        with self.lock:
Tom> +            # If the request is cancelled, don't execute the region.
Tom> +            while len(self.reqs) > 0 and self.reqs[0] <= req:
Tom> +                if heapq.heappop(self.reqs) == req:
Tom> +                    raise KeyboardInterrupt()
Tom> +            # Request is being handled by the gdb thread.
Tom> +            self.in_flight_gdb_thread = req

(see below)

Tom> +        try:
Tom> +            # Execute region.  This may be interrupted by gdb.interrupt.
Tom> +            yield None
Tom> +        finally:
Tom> +            # Request has been handled by the gdb thread,
Tom> +            with self.lock:
Tom> +                self.in_flight_gdb_thread = None
Tom> +

I think it's possible for the interrupt to occur at the marked spot
above -- in_flight_gdb_thread has been set and the lock has been
released.

However, in this case it seems like in_flight_gdb_thread won't be reset?

I'm not really sure if this matters.  However, wouldn't moving the 'with'
block inside the 'try' definitely fix this?

Tom

  reply	other threads:[~2024-02-28 20:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 11:58 [PATCH v2 1/2] [gdb/dap] Move send_gdb and send_gdb_with_response to server module Tom de Vries
2024-02-26 11:58 ` [PATCH v2 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel Tom de Vries
2024-02-28 20:12   ` Tom Tromey [this message]
2024-02-29 14:07     ` Tom de Vries
2024-02-28 20:09 ` [PATCH v2 1/2] [gdb/dap] Move send_gdb and send_gdb_with_response to server module Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o7c0tkk5.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).