Sean-Walker0 opened a new pull request, #7641:
URL: https://github.com/apache/shenyu/pull/7641
Fixes #7637
## Modifications
`ShenyuWebHandler#handle` called `after(exchange)` in a `finally` block
**right after building the (lazy) execution publisher** — the chain uses
`Mono.defer`-style laziness, so the duration was logged and `CHAIN_START_TIME`
was removed before asynchronous request processing even started. Delayed
upstream calls and streaming responses therefore reported
publisher-construction time as chain duration and lost their timing attribute
mid-flight.
The timing/cleanup now runs on the terminal signal of the returned publisher:
```java
before(exchange);
Mono<Void> execute = new DefaultShenyuPluginChain(plugins).execute(exchange);
if (scheduled) {
execute = execute.subscribeOn(scheduler);
}
// the chain is lazy: timing and cleanup must reflect the terminal signal
// of the returned publisher, not its construction
return execute.doFinally(signal -> after(exchange));
```
`doFinally` covers completion, error and cancellation. The **plugin-level**
`before`/`after` hooks are unchanged (the issue explicitly leaves their public
compatibility to a maintainer decision; this PR only fixes the chain-level
timing attribute and its cleanup).
## Verifying this change
- [x] New `ShenyuWebHandlerTest#handleKeepsChainTimingUntilTerminalSignal` —
a plugin returns an externally controlled unfinished `Mono`; after subscribing,
`CHAIN_START_TIME` must still be present, and emitting the terminal signal must
remove it. Red on the pre-fix code (`chain timing must stay active ...
expected: <true> but was: <false>` — the attribute was already cleared at
construction time), green after.
- [x] `./mvnw -pl shenyu-web -am test -B` — full module 94/94 green (all
pre-existing handler cases unchanged), checkstyle clean.
## Notes
- Behavior change: the debug chain-duration log and the `CHAIN_START_TIME`
removal move from publisher construction to the terminal signal
(complete/error/cancel); on the normal WebFlux path the framework subscribes
exactly once, so the cleanup still happens exactly once per request — but now
after the request actually finishes.
- The plugin-level `before`/`after` hooks still fire at construction time;
changing them is a compatibility decision intentionally left out of scope per
the issue.
- Orthogonality: #7572 and #7088 (open) modify other parts of
`ShenyuWebHandler` — neither touches `handle`/`after`/`CHAIN_START_TIME`
(verified by patch inspection).
Make sure that:
- [x] You have read the [contribution
guidelines](https://shenyu.apache.org/community/contributor-guide).
- [x] You submit test cases (unit or integration tests) that back your
changes.
- [x] Your local test passed `./mvnw clean install
-Dmaven.javadoc.skip=true` (module-scoped: `shenyu-web` with `-am`, 94 tests +
checkstyle green).
--
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]