@@ -3801,16 +3801,6 @@ static int prepareCommand(MRCommand *cmd, searchRequestCtx *req, struct MRCtx *m
38013801 return REDISMODULE_OK ;
38023802}
38033803
3804- static searchRequestCtx * createReq (RedisModuleString * * argv , int argc , struct MRCtx * mrctx , QueryError * status ) {
3805- searchRequestCtx * req = rscParseRequest (argv , argc , status );
3806-
3807- if (!req ) {
3808- bailOut (MRCtx_GetBlockedClient (mrctx ), status );
3809- return NULL ;
3810- }
3811- return req ;
3812- }
3813-
38143804int FlatSearchCommandHandler (struct MRCtx * mrctx , RedisModuleBlockedClient * bc , int protocol ,
38153805 RedisModuleString * * argv , int argc , ConcurrentSearchHandlerCtx * handlerCtx ) {
38163806 QueryError status = QueryError_Default ();
@@ -3954,17 +3944,23 @@ int DistSearchCommandImp(RedisModuleCtx *ctx, RedisModuleString **argv, int argc
39543944 return ReplyBlockDeny (ctx , argv [0 ]);
39553945 }
39563946
3957- // Parse the search request on the main thread (non-debug path).
3958- // For debug path, req is created later in DEBUG_FlatSearchCommandHandler.
3959- searchRequestCtx * req = NULL ;
3960- if (!isDebug ) {
3961- QueryError parseStatus = QueryError_Default ();
3962- req = rscParseRequest (argv , argc , & parseStatus );
3963- if (!req ) {
3947+ QueryError parseStatus = QueryError_Default ();
3948+ int parse_argc = argc ;
3949+ if (isDebug ) {
3950+ AREQ_Debug_params debug_params = parseDebugParamsCount (argv , argc , & parseStatus );
3951+ if (QueryError_HasError (& parseStatus )) {
39643952 QueryErrorsGlobalStats_UpdateError (QueryError_GetCode (& parseStatus ), 1 , COORD_ERR_WARN );
3965- QueryError_ReplyAndClear (ctx , & parseStatus );
3966- return REDISMODULE_ERR ;
3953+ return QueryError_ReplyAndClear (ctx , & parseStatus );
39673954 }
3955+ parse_argc = argc - (debug_params .debug_params_count + 2 );
3956+ }
3957+
3958+ // Parse the search request on the main thread so both the standard and debug
3959+ // paths attach req to mrctx before dispatching to the worker thread.
3960+ searchRequestCtx * req = rscParseRequest (argv , parse_argc , & parseStatus );
3961+ if (!req ) {
3962+ QueryErrorsGlobalStats_UpdateError (QueryError_GetCode (& parseStatus ), 1 , COORD_ERR_WARN );
3963+ return QueryError_ReplyAndClear (ctx , & parseStatus );
39683964 }
39693965
39703966 // Create MRCtx on main thread with searchRequestCtx as privdata.
@@ -4372,14 +4368,9 @@ static int DEBUG_FlatSearchCommandHandler(struct MRCtx *mrctx, RedisModuleBlocke
43724368
43734369 int debug_argv_count = debug_params .debug_params_count + 2 ;
43744370 int base_argc = argc - debug_argv_count ;
4375- searchRequestCtx * req = createReq (argv , base_argc , mrctx , & status );
4376-
4377- if (!req ) {
4378- return REDISMODULE_OK ;
4379- }
4380-
4381- // Set req as privdata on mrctx so the reducer and cleanup can access it
4382- MRCtx_SetPrivData (mrctx , req );
4371+ // req was created on the main thread and set as mrctx privdata before dispatch.
4372+ searchRequestCtx * req = MRCtx_GetPrivData (mrctx );
4373+ RS_ASSERT (req );
43834374
43844375 // Copy coordinator queue time for profile output
43854376 req -> coordQueueTime = handlerCtx -> coordQueueTime ;
0 commit comments