diff --git a/rpc/handler.go b/rpc/handler.go
index 92db89e2f8896c78b4873a29c3d7fd99b9a06813..02ab06b6d13102f3a2b6eb3e6ec6805e6db5d534 100644
--- a/rpc/handler.go
+++ b/rpc/handler.go
@@ -151,8 +151,8 @@ func (h *handler) handleMsg(msg *jsonrpcMessage) {
 // call goroutines to shut down.
 func (h *handler) close(err error, inflightReq *requestOp) {
 	h.cancelAllRequests(err, inflightReq)
-	h.cancelRoot()
 	h.callWG.Wait()
+	h.cancelRoot()
 	h.cancelServerSubscriptions(err)
 }