Skip to content

Commit

Permalink
proxy: fix issue with waiting on subreqs
Browse files Browse the repository at this point in the history
If a rctx enqueues N subrctx's, then issues a wait, but all of the
subrctx's fast fail... if you then issue another wait API call the
parent will get resumed recursively before the child is completed.

Meaning the parent won't resume the coroutine if the subrctx's did _not_
match the wait condition (ie: looking for WAIT_GOOD and got WAIT_ANY).

To be honest the issue is so complex but the fix so simple I'm not going
to attempt to describe it past this point.
  • Loading branch information
dormando committed Dec 17, 2024
1 parent 4c56c8d commit a2dac19
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions proxy_luafgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ static void mcp_resume_rctx_from_cb(mcp_rcontext_t *rctx) {
if (rctx->parent) {
struct mcp_rqueue_s *rqu = &rctx->parent->qslots[rctx->parent_handle];
if (res == LUA_OK) {
mcp_rcontext_t *parent = rctx->parent;
int handle = rctx->parent_handle;
int type = lua_type(rctx->Lc, 1);
mcp_resp_t *r = NULL;
if (type == LUA_TUSERDATA && (r = luaL_testudata(rctx->Lc, 1, "mcp.response")) != NULL) {
Expand All @@ -963,10 +965,12 @@ static void mcp_resume_rctx_from_cb(mcp_rcontext_t *rctx) {
// generate a generic object with an error.
_mcp_resume_rctx_process_error(rctx, rqu);
}
if (rctx->parent->wait_count) {
mcp_process_rctx_wait(rctx->parent, rctx->parent_handle);
}

// return ourself before telling the parent to wait.
mcp_funcgen_return_rctx(rctx);
if (parent->wait_count) {
mcp_process_rctx_wait(parent, handle);
}
} else if (res == LUA_YIELD) {
// normal.
_mcp_queue_hack(rctx->c);
Expand Down

0 comments on commit a2dac19

Please sign in to comment.