提交 a5445a37 编写于 作者: N Nikolay Shirokovskiy 提交者: Michal Privoznik

rpc: fix race on stream abort/finish and server side abort

Stream abort/finish can hang because we can receive abort message
from server and yet sent abort/finish message to server. The latter
will not be answered ever because after server sends abort message
it forgets the stream and messages for unknown stream are simply ignored.

We check for stream error at the very beginning of remoteStreamFinish/remoteStreamAbort
but stream error can be set after the check in another thread operating
on stream. Let's check for stream error under client lock similar
to what's done in [1].

[1] 833b901c: stream: Check for stream EOF
Signed-off-by: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
上级 df2b31ff
......@@ -2216,20 +2216,26 @@ int virNetClientSendWithReplyStream(virNetClientPtr client,
virNetMessagePtr msg,
virNetClientStreamPtr st)
{
int ret;
int ret = -1;
virObjectLock(client);
/* Other thread might have already received
* stream EOF so we don't want sent anything.
* Server won't respond anyway.
*/
if (virNetClientStreamEOF(st)) {
virObjectUnlock(client);
return 0;
if (virNetClientStreamRaiseError(st))
goto cleanup;
/* Check for EOF only if we are going to wait for incoming data */
if (!msg->bufferLength && virNetClientStreamEOF(st)) {
ret = 0;
goto cleanup;
}
ret = virNetClientSendInternal(client, msg, true, false);
if (virNetClientSendInternal(client, msg, true, false) < 0)
goto cleanup;
ret = 0;
cleanup:
virObjectUnlock(client);
if (ret < 0)
return -1;
return 0;
return ret;
}
......@@ -350,7 +350,7 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
if (virNetMessageEncodePayloadRaw(msg, NULL, 0) < 0)
goto error;
if (virNetClientSendWithReply(client, msg) < 0)
if (virNetClientSendWithReplyStream(client, msg, st) < 0)
goto error;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册