From: Peter Xu <peterx@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
"John Snow" <jsnow@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] monitor: postpone monitor_qmp_cleanup_queues
Date: Fri, 8 Jun 2018 12:42:35 +0800 [thread overview]
Message-ID: <20180608044235.GA7736@xz-mi> (raw)
In-Reply-To: <87tvqeyfs2.fsf@dusky.pond.sub.org>
On Thu, Jun 07, 2018 at 01:53:01PM +0200, Markus Armbruster wrote:
> Peter Xu <peterx@redhat.com> writes:
>
> > Previously we cleanup the queues when we got CLOSED event. It was used
>
> we clean up
>
> > to make sure we won't leftover replies/events of a old client to a new
>
> we won't send leftover replies/events of an old client
>
> > client. Now this patch postpones that until OPENED.
>
> What if OPENED never comes?
Then we clean that up until destruction of the monitor. IMHO it's
fine, but I'm not sure whether that's an overall acceptable approach.
>
> > In most cases, it does not really matter much since either way will make
> > sure that the new client won't receive unexpected old events/responses.
> > However there can be a very rare race condition with the old way when we
> > use QMP with stdio and pipelines (which is quite common in iotests).
> > The problem is that, we can easily have something like this in scripts:
> >
> > cat $QMP_COMMANDS | qemu -qmp stdio ... | filter_commands
> >
> > In most cases, a QMP session will be based on a bidirectional
> > channel (read/write to a TCP port, for example), so IN and OUT are
> > sharing some fundamentally same thing. However that's untrue for pipes
>
> Suggest "are fundamentally the same thing".
>
> > above - the IN is the "cat" program, while the "OUT" is directed to the
> > "filter_commands" which is actually another process.
>
> Regarding 'IN is the "cat" program': a pipe is not a program. Suggest
> 'IN is connected to "cat", while OUT is connected to "filter_commands",
> which are separate processes.
>
> > Now when we received the CLOSED event, we cleanup the queues (including
>
> we clean up
>
> > the QMP response queue). That means, if we kill/stop the "cat" process
> > faster than the filter_commands process, the filter_commands process is
> > possible to miss some responses/events that should belong to it.
>
> I'm not sure I understand the error scenario. Can you explain it in
> more concrete terms? Like "cat terminates, QEMU reads EOF, QEMU does
> this, QEMU does that, oops, it shouldn't have done that".
One condition could be this (after "quit" command is executed and QEMU
quits the main loop):
1. [main thread] QEMU queues one SHUTDOWN event into response queue
2. "cat" terminates (to distinguish it from the animal, I quote it).
Logically it can terminate even earlier, but let's just assume it's
here.
3. [monitor iothread] QEMU reads EOF from stdin, which connects to the
"cat" process
4. [monitor iothread] QEMU calls the CLOSED event hook for the monitor,
which will clean up the response queue of the monitor, then the
SHUTDOWN event is dropped
5. [main thread] clean up the monitors in monitor_cleanup(), when
trying to flush pending responses, it sees nothing. SHUTDOWN is
lost forever
Note that before the monitor iothread was introduced, step [4]/[5]
could never happen since the main loop was the only place to detect
the EOF event of stdin and run the CLOSED event hooks. Now things can
happen in parallel in the iothread.
I can add these into commit message.
>
> > In practise, I encountered a very strange SHUTDOWN event missing when
>
> practice
>
> May I suggest use of a spell checker? ;)
Sorry for that. TODO added: "Find a spell checker for Emacs".
>
> > running test with iotest 087. Without this patch, iotest 078 will have
>
> 087 or 078?
087. Err. Even a spell checker won't help me here!
>
> > ~10% chance to miss the SHUTDOWN event and fail when with Out-Of-Band
> > enabled:
> >
> > 087 8s ... - output mismatch (see 087.out.bad)
I'll take all the rest comments. Thanks for reviewing.
--
Peter Xu
next prev parent reply other threads:[~2018-06-08 4:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 8:06 [Qemu-devel] [PATCH] monitor: postpone monitor_qmp_cleanup_queues Peter Xu
2018-06-04 15:01 ` Marc-André Lureau
2018-06-05 3:39 ` Peter Xu
2018-06-07 11:53 ` Markus Armbruster
2018-06-08 4:42 ` Peter Xu [this message]
2018-06-08 7:05 ` Markus Armbruster
2018-06-08 8:04 ` Stefan Hajnoczi
2018-06-08 8:18 ` Markus Armbruster
2018-06-08 9:11 ` Peter Xu
2018-06-08 9:24 ` Peter Xu
2018-06-11 7:58 ` Markus Armbruster
2018-06-11 16:45 ` Stefan Hajnoczi
2018-06-12 5:47 ` Peter Xu
2018-06-13 14:30 ` Stefan Hajnoczi
2018-06-14 3:05 ` Peter Xu
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=20180608044235.GA7736@xz-mi \
--to=peterx@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 NNTP newsgroup(s).