Aias00 opened a new issue, #7637: URL: https://github.com/apache/shenyu/issues/7637
## Problem The gateway's chain timing ends when `handle()` returns a `Mono`, before asynchronous request processing finishes. Delayed upstream calls and streaming responses therefore report publisher-construction time as chain duration. Verified by source inspection at `b4e115367`; terminal-signal regression tests are required. Suggested priority: P2. ## Evidence and reproduction [ShenyuWebHandler.handle](https://github.com/apache/shenyu/blob/b4e115367fd57adc8aba332d655b1009932ba394/shenyu-web/src/main/java/org/apache/shenyu/web/handler/ShenyuWebHandler.java#L123) calls `before(exchange)`, returns the execution publisher, then immediately calls `after(exchange)` in `finally`. `after` logs duration and removes `CHAIN_START_TIME`. The chain itself uses `Mono.defer`, so plugin execution starts later on subscription. A deterministic reproduction can use a plugin returning an externally controlled, unfinished `Mono`: obtain the handler publisher, subscribe, keep the plugin unfinished, and assert that request-end timing/cleanup has not run until completion, error, or cancellation. Virtual time can cover elapsed duration. The [plugin-level before/after hooks](https://github.com/apache/shenyu/blob/b4e115367fd57adc8aba332d655b1009932ba394/shenyu-web/src/main/java/org/apache/shenyu/web/handler/ShenyuWebHandler.java#L304) also surround publisher creation. Their public compatibility needs an explicit decision rather than an incidental behavior change. ## Proposed scope First fix the gateway-level lifecycle using subscription-time initialization and terminal-signal cleanup (for example, `Mono.defer` plus `doFinally`). Define and document what duration is measured, including scheduler placement. Keep lifecycle cleanup once per subscription and preserve error propagation. Audit existing plugin hook implementations. If `after` is intentionally a publisher-construction hook, document it; otherwise introduce a separately reviewed compatibility-safe correction. This issue does not require new tracing dependencies or a distributed tracing redesign. ## Acceptance criteria - [ ] Creating the handler publisher does not record a completed request. - [ ] Delayed execution contributes to the documented chain duration. - [ ] Completion, asynchronous failure, synchronous plugin failure, and cancellation each perform cleanup exactly once per subscription. - [ ] Scheduled and unscheduled paths are covered with deterministic Reactor tests. - [ ] Existing plugin-hook callers are reviewed and the hook semantics/compatibility decision is documented. ## Related #5475 introduced plugin/chain lifecycle hooks. #7566 tracks broader distributed tracing; this is a focused lifecycle/timing correctness fix that can be delivered independently. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
