#1956·kitex

如果 kitex 使用 ServiceMiddleware 进行注册,则会导致该中间件最终执行多次

作者: kom0055创建于 2026年5月13日更新于 2026年5月13日

The problem is that the next variable is re-assigned, which causes the closure variable to be corrupted. Originally, the call stack was next1->next2->next3->next4, but when next3 is executed, the closure variable is replaced with next, resulting in next1->next2->next3->next5->next4->invoke; if it is called again, it becomes next1->next2->next3->next5->next5->next4->invoke, and as the number of calls increases, this chain will grow linearly, leading to an unexpected number of executions, which in turn causes the runtime call stack to overflow. Not to mention the more complex problems in concurrent situations.

内容来源: cloudwego/kitex