nbd/server: fix: check client->closing before sending reply
commita0d7ce20a94ba66e1d9577429a62d133f1cd19cf
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Thu, 8 Mar 2018 18:46:34 +0000 (8 21:46 +0300)
committerEric Blake <eblake@redhat.com>
Tue, 13 Mar 2018 20:38:55 +0000 (13 15:38 -0500)
treeedd22e2e0c4e8952dd8b7e65f7461bdc9ba4d0c1
parent37e02aebf88f8a12f02457de207b09b607c1e8a8
nbd/server: fix: check client->closing before sending reply

Since the unchanged code has just set client->recv_coroutine to
NULL before calling nbd_client_receive_next_request(), we are
spawning a new coroutine unconditionally, but the first thing
that coroutine will do is check for client->closing, making it
a no-op if we have already detected that the client is going
away.  Furthermore, for any error other than EIO (where we
disconnect, which itself sets client->closing), if the client
has already gone away, we'll probably encounter EIO later
in the function and attempt disconnect at that point.  Logically,
as soon as we know the connection is closing, there is no need
to try a likely-to-fail a response or spawn a no-op coroutine.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20180308184636.178534-4-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: squash in further reordering: hoist check before spawning
next coroutine, and document rationale in commit message]
Signed-off-by: Eric Blake <eblake@redhat.com>
nbd/server.c