From 333c54ebbfa63057f5e86e7b358206daabfd8d02 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 11 Aug 2024 00:00:13 +0300 Subject: [PATCH] Cleanup clients correctly during stop(). Was also affecting #67, but could also reproduce during normal operation --- src/nfs/nfs_proxy.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nfs/nfs_proxy.cpp b/src/nfs/nfs_proxy.cpp index d5e173b2..9b8f6abc 100644 --- a/src/nfs/nfs_proxy.cpp +++ b/src/nfs/nfs_proxy.cpp @@ -695,6 +695,8 @@ void nfs_client_t::handle_read(int result) frag_num++; } } + // Increase client refcount while the RPC call is being processed + refs++; // Handle full message int referenced = handle_rpc_message(cur_buffer.buf, data+4, wanted-4*fragments); cur_buffer.refs += referenced ? 1 : 0; @@ -776,11 +778,11 @@ bool nfs_client_t::deref() void nfs_client_t::stop() { - parent->rpc_clients.erase(nfs_fd); - parent->active_connections--; stopped = true; if (refs <= 0) { + parent->rpc_clients.erase(nfs_fd); + parent->active_connections--; parent->epmgr->tfd->set_fd_handler(nfs_fd, true, NULL); close(nfs_fd); delete this; @@ -836,6 +838,10 @@ void nfs_client_t::handle_send(int result) } } free(rop); + if (deref()) + { + return; + } } result -= iov.iov_len; done++;