From: Markus Armbruster <armbru@redhat.com>
To: Stefan Reiter <s.reiter@proxmox.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Wolfgang Bumiller <w.bumiller@proxmox.com>,
Michael Roth <michael.roth@amd.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Thomas Lamprecht <t.lamprecht@proxmox.com>
Subject: Re: [PATCH] monitor/qmp: fix race with clients disconnecting early
Date: Thu, 02 Sep 2021 14:45:16 +0200 [thread overview]
Message-ID: <871r67b0yr.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <87eea9wrcf.fsf@dusky.pond.sub.org> (Markus Armbruster's message of "Tue, 31 Aug 2021 17:45:20 +0200")
I've thought a bit more.
A monitor can serve a series of clients.
Back when all of the monitor ran in the main thread, we completely
finished serving the current client before we started serving the next
one (I think). In other words, sessions did not overlap.
Since we moved parts of the monitor to the monitor I/O thread (merge
commit 4bdc24fa018), sessions can overlap, and this causes issues, as
you demonstrated.
Possible fixes:
1. Go back to "don't overlap" with suitable synchronization.
I'm afraid this won't cut it, because exec-oob would have wait in
line behind reconnect.
It currently waits for other reasons, but that feels fixable. Going
back to "don't overlap" would make it unfixable.
2. Make the lingering session not affect / be affected by the new
session's state
This is what your patch tries. Every access of session state needs
to be guarded like
if (conn_nr_before == qatomic_read(&mon->connection_nr)) {
access session state
} else {
???
}
Issues:
* We have to find and guard all existing accesses. That's work.
* We have to guard all future accesses. More work, and easy to
forget, which makes this fix rather brittle.
* The fix is spread over many places.
* We may run into cases where the ??? part gets complicated.
Consider file descriptors. The command in flight will have its
monitor_get_fd() fail after disconnect. Probably okay, because it
can also fail for other reasons. But we might run into cases where
the ??? part creates new failure modes for us to handle.
3. Per-session state
Move per-session state from monitor state into a separate object.
Use reference counts to keep this object alive until both threads are
done with the session.
Monitor I/O thread executes monitor core and the out-of-band
commands; its stops using the old session on disconnect, and starts
using the new session on connect.
Main thread executes in-band commands, and these use the session that
submitted them.
Do I make sense, or should I explain my idea in more detail?
next prev parent reply other threads:[~2021-09-03 13:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-23 10:11 [PATCH] monitor/qmp: fix race with clients disconnecting early Stefan Reiter
2021-08-23 15:05 ` Philippe Mathieu-Daudé
2021-08-25 15:54 ` Markus Armbruster
2021-08-26 13:50 ` Markus Armbruster
2021-08-26 15:15 ` Stefan Reiter
2021-08-31 15:45 ` Markus Armbruster
2021-09-02 12:05 ` Markus Armbruster
2021-09-02 12:45 ` Markus Armbruster [this message]
2021-10-12 9:27 ` Markus Armbruster
2021-10-13 15:44 ` Stefan Reiter
2021-10-14 5:40 ` Markus Armbruster
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=871r67b0yr.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=kwolf@redhat.com \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=s.reiter@proxmox.com \
--cc=t.lamprecht@proxmox.com \
--cc=w.bumiller@proxmox.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).