From 2ffd2c0950fa34c649b7f12eecbf2e6c55286df0 Mon Sep 17 00:00:00 2001 From: Coldwings Date: Wed, 16 Apr 2025 16:27:00 +0800 Subject: [PATCH] Fix on RPC async_serve accessing count after context call --- rpc/rpc.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rpc/rpc.cpp b/rpc/rpc.cpp index dbfecb10..0d9e0618 100644 --- a/rpc/rpc.cpp +++ b/rpc/rpc.cpp @@ -236,6 +236,8 @@ namespace rpc { COPY(func); COPY(stream); COPY(sk); + COPY(stream_serv_count); + COPY(stream_cv); COPY(w_lock); #undef COPY } @@ -375,14 +377,14 @@ namespace rpc { } static void* async_serve(void* args_) { - auto ctx = (Context*)args_; - Context context(std::move(*ctx)); - ctx->got_it = true; + bool &got_it = ((Context*)args_)->got_it; + Context context(std::move(*(Context*)args_)); + got_it = true; thread_yield(); context.serve_request(); // serve done, here reduce refcount - (*ctx->stream_serv_count) --; - ctx->stream_cv->notify_all(); + (*context.stream_serv_count) --; + context.stream_cv->notify_all(); return nullptr; } virtual int shutdown(bool no_more_requests) override {