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,  Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel
Date: Fri, 23 Feb 2024 10:27:05 -0700	[thread overview]
Message-ID: <87jzmvxf9y.fsf@tromey.com> (raw)
In-Reply-To: <20240223165128.32211-2-tdevries@suse.de> (Tom de Vries's message of "Fri, 23 Feb 2024 17:51:28 +0100")

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> 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

  reply	other threads:[~2024-02-23 17:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-23 16:51 [PATCH 1/2] [gdb/dap] Move send_gdb_with_response to server module Tom de Vries
2024-02-23 16:51 ` [PATCH 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel Tom de Vries
2024-02-23 17:27   ` Tom Tromey [this message]
2024-02-26 12:24     ` Tom de Vries

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=87jzmvxf9y.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).