mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
rpc: Fix client crash on connection close
A multi-threaded client with event loop may crash if one of its threads closes a connection while event loop is in the middle of sending keep-alive message (either request or response). The right place for it is inside virNetClientIOEventLoop() between poll() and virNetClientLock(). We should only close a connection directly if no-one is using it and defer the closing to the last user otherwise. So far we only did so if the close was initiated by keep-alive timeout.
This commit is contained in:
parent
57e677a7c6
commit
720bee3008
@ -108,8 +108,6 @@ struct _virNetClient {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void virNetClientRequestClose(virNetClientPtr client);
|
|
||||||
|
|
||||||
static void virNetClientLock(virNetClientPtr client)
|
static void virNetClientLock(virNetClientPtr client)
|
||||||
{
|
{
|
||||||
virMutexLock(&client->lock);
|
virMutexLock(&client->lock);
|
||||||
@ -253,7 +251,7 @@ virNetClientKeepAliveStart(virNetClientPtr client,
|
|||||||
static void
|
static void
|
||||||
virNetClientKeepAliveDeadCB(void *opaque)
|
virNetClientKeepAliveDeadCB(void *opaque)
|
||||||
{
|
{
|
||||||
virNetClientRequestClose(opaque);
|
virNetClientClose(opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -512,19 +510,11 @@ virNetClientCloseLocked(virNetClientPtr client)
|
|||||||
|
|
||||||
void virNetClientClose(virNetClientPtr client)
|
void virNetClientClose(virNetClientPtr client)
|
||||||
{
|
{
|
||||||
|
VIR_DEBUG("client=%p", client);
|
||||||
|
|
||||||
if (!client)
|
if (!client)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virNetClientLock(client);
|
|
||||||
virNetClientCloseLocked(client);
|
|
||||||
virNetClientUnlock(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
virNetClientRequestClose(virNetClientPtr client)
|
|
||||||
{
|
|
||||||
VIR_DEBUG("client=%p", client);
|
|
||||||
|
|
||||||
virNetClientLock(client);
|
virNetClientLock(client);
|
||||||
|
|
||||||
/* If there is a thread polling for data on the socket, set wantClose flag
|
/* If there is a thread polling for data on the socket, set wantClose flag
|
||||||
|
Loading…
x
Reference in New Issue
Block a user