On 01/23/2014 03:54 PM, Luiz Capitulino wrote:
> On Thu, 23 Jan 2014 08:44:02 -0500
> Luiz Capitulino <
lcapi...@redhat.com> wrote:
>
>> On Thu, 23 Jan 2014 19:23:51 +0800
>> Fam Zheng <
fa...@redhat.com> wrote:
>>
>>> Bcc:
>>> Subject: Re: [Qemu-devel] Possible bug in monitor code
>>> Reply-To:
>>> In-Reply-To: <
52E0EC4B...@grnet.gr>
>>>
>>> On Thu, 01/23 12:17, Stratos Psomadakis wrote:
>>>> On 01/23/2014 05:07 AM, Fam Zheng wrote:
>>>>> On Wed, 01/22 17:53, Stratos Psomadakis wrote:
>>>>>> Hi,
>>>>>>
>>>>>> we've encountered a weird issue regarding monitor (qmp and hmp) behavior
>>>>>> with qemu-1.7 (and qemu-1.5). The following steps will reproduce the issue:
>>>>>>
>>>>>> 1) Client A connects to qmp socket with socat
>>>>>> 2) Client A gets greeting message {"QMP": {"version": ..}
>>>>>> 3) Client A waits (select on the socket's fd)
>>>>>> 4) Client B tries to connect to the *same* qmp socket with socat
>> QMP/HMP can only handle a single client per connection, so this is
>> not supported. What you could do is to create multiple QMP/HMP instances
>> on the command-line, but this has never been fully tested so we don't
>> officially support this either (although it may work).
>>
>> Now, not gracefully failing on step 4 is a real bug here. I think the
>> best thing to do would be to close client's B connection. Patches are
>> welcome :)
> Thinking about this again, I think this should already be the case
> (as I don't believe chardev code is sitting on accept()). So maybe
> you triggered a race on chardev code or broke something there.
Yes, the chardev code doesn't accept any more connections until the
currently active connection is closed.
However, when a new client tries to connect (while there's another qmp /
hmp connection active) the kernel, as long as there's room in the socket
backlog, will return to the client that the connection has been
successfully established and will queue the connection to be accepted
later, when qmp actually finishes with its active connection and
re-executes accept().
The problem arises if the new client closes the connection before the
older one is finished. When qmp runs accept() again, it will get a
socket fd for a client who has now closed the connection. At this point,
the monitor control event handler will get triggered and try to write /
flush the greeting message to the client. The client however has closed
its socket so the write will fail with SIGPIPE / EPIPE. Neither the
qemu-char nor the monitor code seem to handle this situation.
Btw, have you tried to reproduce it?
Thanks,
Stratos
>
>>>>>> 5) Client B does *NOT* get any greating message
>>>>>> 6) Client B waits (select on the socket's fd)
>>>>>> 7) Client B closes connection (kill socat)
>>>>>> 8) Client A quits too
>>>>>> 9) Client C connects to qmp socket
>>>>>> 10) Client C gets *two* greeting messages!!!
>>>>> Hi Stratos, thank you for debugging and reporting this.
>>>>>
>>>>> I tested this sequence but can't fully reproduce this. What I see is 5) but no
>>>>> 10). Client C acts normally. And your patch below doesn't solve it for me.
>>>> Hm, which qemu version (or repo branch / tag) did you use? We did a
>>>> quick scan of the master branch code / commits, but we didn't find
>>>> anything that might fix the issue.
>>> I tried on qemu.git master, and also 1.7. I think it is a bug: in my test, step
>>> 5), B not getting any greeting message.
>>>
>>> But I get only one greeting message in step 10), which is a bit different from
>>> what you reported.
>>>
>>> And no difference with your patch applied.
>>>
>>> Cc'ing Luiz who maintains the monitor code and may have more ideas.
>>>
>>> Thanks,
>>>
>>> Fam
--
Stratos Psomadakis
<
pso...@grnet.gr>