diff options
author | Jiri Denemark <jdenemar@redhat.com> | 2012-03-02 19:57:27 +0100 |
---|---|---|
committer | Jiri Denemark <jdenemar@redhat.com> | 2012-03-05 11:30:02 +0100 |
commit | 720bee300896a0e66d47e391be7cd86719697075 (patch) | |
tree | c9a8b5bb33b22f363afe693cca47a92ad03db0f1 /src/rpc/virnetclient.c | |
parent | 57e677a7c6e55dea60d9be5667e8eebba11cc2b4 (diff) | |
download | libvirt-720bee300896a0e66d47e391be7cd86719697075.tar.gz |
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.
Diffstat (limited to 'src/rpc/virnetclient.c')
-rw-r--r-- | src/rpc/virnetclient.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index ffe067c76d..99ab8007f2 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -108,8 +108,6 @@ struct _virNetClient { }; -static void virNetClientRequestClose(virNetClientPtr client); - static void virNetClientLock(virNetClientPtr client) { virMutexLock(&client->lock); @@ -253,7 +251,7 @@ virNetClientKeepAliveStart(virNetClientPtr client, static void virNetClientKeepAliveDeadCB(void *opaque) { - virNetClientRequestClose(opaque); + virNetClientClose(opaque); } static int @@ -512,20 +510,12 @@ virNetClientCloseLocked(virNetClientPtr client) void virNetClientClose(virNetClientPtr client) { + VIR_DEBUG("client=%p", client); + if (!client) return; virNetClientLock(client); - virNetClientCloseLocked(client); - virNetClientUnlock(client); -} - -static void -virNetClientRequestClose(virNetClientPtr client) -{ - VIR_DEBUG("client=%p", client); - - virNetClientLock(client); /* If there is a thread polling for data on the socket, set wantClose flag * and wake the thread up or just immediately close the socket when no-one |