Repository navigation
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Stream Agent analysis
The rule timeout is applied to the entire upstream WebSocket session Mono rather than the handshake only, so an established idle session outliving the rule timeout is terminated — the exact regression the PR says it avoids. CI is also not green.
Evidence: ["WebSocketPlugin.java RIGHT line 422: upstream.timeout(Duration.ofMillis(this.timeout), Mono.error(new TimeoutException(...))) is applied directly to the Mono returned by client.execute (assigned at RIGHT line 392). The PR body itself states client.execute's Mono 'completes only when the session ends', so this bounds the whole proxied session, not the handshake.","The comment at RIGHT lines 419-420 claims 'The established session ... is never bounded by this timer' and the body says the first cut's wrapping of client.execute was the mistake supposedly moved off — both are contradicted by the implemented code.","CI not passing: pr_build completed with 'failure', build/e2e checks queued and policy checks cancelled; passed=false, pending=true, diagnosis=CI_PENDING. Full diff available in FULL_DIFF attachment; auxiliary pinned-source reads failed, so no further source context was used."]
Next steps: ["Bound only the connection/upgrade phase (e.g., the connect/handshake signal), not the Mono returned by client.execute which completes only when the upstream session closes.","Add a test with an established, idle upstream session proving it survives past the rule timeout, to distinguish handshake timeout from session timeout.","Re-run CI before merge: pr_build reported failure and several build/e2e/policy checks are queued or cancelled (passed=false, pending=true)."]
Verdict: NEEDS_CHANGES; publication: REQUEST_CHANGES (VERIFIED_BLOCKING_FINDINGS)
Findings: [{"line":422,"message":"The timeout is applied via upstream.timeout(...) to the Mono returned by client.execute, which only completes when the upstream WebSocket session closes. This bounds the entire established session rather than the handshake, so a healthy idle session outliving the rule timeout is terminated with TimeoutException — the idle-close regression (#8377) the change says it avoids, and directly contradicting the adjacent comment that the session is never bounded. The two tests use Mono.never(), which models an established idle session just as well as a stalled handshake, so they cannot detect this.","path":"shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/WebSocketPlugin.java","severity":"HIGH","side":"RIGHT"}]
Scope: captured GitHub evidence only; no local tests were executed.
Task: 0cad282a-dd97-4739-83ef-900406aca35d Commit: 9ea681f3538750b944dcc86d9c4fe6f63498fcba
wy471x
left a comment
There was a problem hiding this comment.
Standards
Mono.error(new TimeoutException(...))uses a JDK exception; the project convention (AGENTS.md) prefersShenyuExceptionor a custom exception for failures surfaced by plugins. It is also instantiated eagerly on every request, capturing a stack trace even when the operator never fires — pass a supplier.- The constructor now takes a bare
long timeoutwhose unit lives only in the javadoc.Durationwould carry the unit into the type. - Import order in the new test interleaves
org.junit.*,reactor.test.*andjava.*; the existing tests in this module keepjava.*after the third-party imports. Not tooling-enforced, but the repo asks for surrounding style. mockChain()returnsorg.apache.shenyu.plugin.api.ShenyuPluginChainas an inline fully-qualified name — use an import.
Spec
The issue states: "Applying a timeout to the entire session Mono would also be incorrect, because it would terminate healthy long-lived connections at a fixed age."
- Blocking (verified).
client.execute(...)does not complete when the upgrade finishes.ReactorNettyWebSocketClient.executeends with.handle((inbound, outbound) -> handler.handle(session)).next(), so the returnedMono<Void>completes only when the proxied handler's Mono — the session lifetime — completes. Wrapping it in.timeout(...)therefore bounds the established session: aMono<Void>never emits, sotimeoutfires on the missingonComplete. SinceWebSocketRuleHandle.timeoutdefaults toConstants.TIME_OUT = 3000, every proxied session is torn down 3 s after establishment regardless of traffic — strictly worse than the reported idle close, which at least reset on traffic. The javadoc added toShenyuWebSocketHandler("bound the upstream handshake … the established session keeps running on its own subscription") does not hold for this reason. - The new test cannot catch the defect:
when(webSocketClient.execute(any(), any(), any())).thenReturn(Mono.never())is indistinguishable between a stalled handshake and a live session. Please add a test where the proxied session stays open beyondtimeoutand assert it is not closed (aStepVerifierover the handler Mono, or a real socket test as the issue's validation asks for). - Missing behaviour: the issue asks for two separate controls — a connection/upgrade deadline that stops once the upgrade succeeds, plus an optional
idleTimeout(0 disables) — with Admin validation and form metadata. This PR adds one field applied to the wrong boundary, so the second control is unimplemented. - Minor: a session killed by this timer after the
101has already been sent will surface as an abrupt close without a status code or reason, which is one of the symptoms the issue reports.
Verdict
Request changes. Apply the deadline where the upstream upgrade is actually awaited (a reactor-netty connect/response timeout, or a timeout around the handshake before the session Mono is returned) and leave the session Mono untimed; then prove it with a test that outlives the configured timeout.
…handshake The WebSocket rule exposes a timeout setting (WebSocketRuleHandle parses and caches it), but nothing consumed it end to end: the upstream websocket handshake had no deadline at all. PR apache#8377 already fixed the symptom the issue reports — idle sessions closing after ~3 seconds — by removing the shared HTTP client's timeout handlers from websocket connections; the remaining ask is making the rule's timeout mean something. The rule timeout now bounds the upstream handshake only: the client.execute(...) Mono inside ShenyuWebSocketHandler is wrapped with a rule-driven deadline, so a dead upstream fails the upgrade in a rule-controlled time instead of hanging. The established session keeps running on its own subscription and is never bounded by this timer — websocket sessions are legitimately idle, and a session-wide timer would re-introduce the idle-close bug apache#8377 fixed. A non-positive timeout disables the deadline. The rule's retry field remains unused, as in the divide plugin's websocket-facing path.
… the session mono Review of the first cut wrapped client.execute(...) with the rule timeout, but that Mono completes when the proxied session ends — a healthy long-lived session would have been killed at a fixed age, exactly what the issue warns about. The deadline now wraps the handshake Mono the plugin returns (which completes when the upgrade finishes, while the session runs on its own subscription), on all three load balancer paths, and the handler no longer carries the timeout.
…dd an opt-in idle timeout
9ea681f to
4767e50
Compare
Second-round review responseThanks @wy471x and @Aias00. Both blocking points are addressed in The timeout no longer bounds the session. You are right that The second control is implemented. Tests. CI. The red build was |
Aias00
left a comment
There was a problem hiding this comment.
Stream Agent analysis
Reviewed #8513 at d916652 in full. The change applies the WebSocket rule timeout to the upstream handshake via a Sinks.Empty upgrade signal (deadline becomes inert after upgrade), adds an opt-in idleTimeout with dual-direction activity tracking, adds an Admin handle validator, and adds form metadata to 4 init and 6 upgrade SQL scripts. The two blocking points from the prior CHANGES_REQUESTED review appear addressed and I found no concrete HIGH/CRITICAL defect, but CI is still pending, so PASS is not permitted.
Evidence: ["Full frozen diff read: resource_diff paged from offset 0 through 56125 with has_more=false, covering all 20 changed files; SHA256 856cc032... matches pinned comparison.","Core contract verified at head: ShenyuWebSocketHandler.handle emits upgraded.tryEmitEmpty() in the inner handler and uses upgraded.asMono().timeout(...).switchIfEmpty(Mono.never()) so the deadline goes inert after upgrade; pipe() applies idleWatch on both receive directions with GOING_AWAY/1001; the single production constructor call site (WebSocketPlugin.java:126) and the tests use the new 5-arg constructor; WebSocketRuleHandleValidator is wired into create/update/registerDefault via validateRuleHandle.","CI not passing: evidence attachment reports check_count 47, passed=false, pending=true, diagnosis CI_PENDING, with pr_build/plugin_contract/rat_check and multiple build jobs queued or in_progress and no failed checks yet."]
Next steps: ["Wait for the queued/in_progress CI checks (pr_build, plugin_contract, rat_check, native-sql, integrated websocket builds, etc.) to finish and confirm green, then re-run this review for a PASS verdict."]
Verdict: INCONCLUSIVE; publication: COMMENT (DIFF_DELIVERY_INCOMPLETE)
Findings: []
Scope: captured GitHub evidence only; no local tests were executed.
Task: ab8b6527-e9cc-4895-b63e-7b01ca93f8be Commit: d91665289d6f1945d846b0b456a54d770457a2a5
Fixes #8474.
The WebSocket rule exposes
timeout, andWebSocketRuleHandleparsed and cached it, but nothing consumed it: the upstream websocket handshake had no deadline at all. PR #8377 already fixed the symptom the issue reports — idle sessions closing after about three seconds — by removing the shared HTTP client's timeout handlers from websocket connections; the remaining ask is making the rule timeout mean something, with the two controls the issue describes.What changed
The rule
timeoutnow bounds the upstream connection and upgrade only.ReactorNettyWebSocketClient.executereturns a Mono that completes when the proxied session ends, so a deadline on it closes healthy sessions at a fixed age. Instead, the inner upstream handler completes a handshake signal as its first statement — the only observable point at which the upgrade succeeded — and the plugin races the connection against a deadline built on that signal. Once the signal fires, the deadline turns inert and the session runs untimed; a stalled upgrade is closed with1011and an explicit reason, and the pending connection attempt is cancelled. A non-positivetimeoutdisables the deadline.A separate opt-in
idleTimeout(milliseconds, default0= disabled) applies after establishment. Both receive directions count as activity, and a session that moved no message for the configured period is closed on both sides with1001and an explicit reason; traffic in either direction keeps the session alive, and no timer exists whenidleTimeoutis zero or below. Admin rejects negativetimeoutoridleTimeouthandles through a newWebSocketRuleHandleValidatorwired into rule create, update and import, and the rule form gains anidleTimeoutfield in the MySQL, PostgreSQL, Oracle and H2 init schemas plus the six 2.7.2 to 2.7.3 upgrade scripts. The rule'sretryfield remains unused, as in the divide plugin's websocket-facing path.Testing
WebSocketPluginHandshakeTimeoutTestdrives the real plugin with captured sessions. A permanently stalled upgrade under a 100 ms rule timeout is closed with1011and a reason and the plugin Mono completes. The regression case for the earlier mistake models an upgrade that succeeds after 20 ms while the rule timeout is 100 ms: the session then stays silent and nothing is closed for 400 ms, so the deadline cannot bound an established session. Idle expiry closes with1001and a reason, 30 ms traffic keeps a 100 ms idle limit alive, and bothidleTimeout=0and a non-positivetimeoutdisable their controls.WebSocketPluginTestkeeps the leastActive and shortestResponse coverage and now constructs the handler directly instead of by reflection, which also fixed the red CI build.WebSocketRuleHandleValidatorTestand newRuleServiceTestcases pin Admin rejection before any write.Local results:
shenyu-plugin-websocket29/29,WebSocketRuleHandleTest4/4, Admin validator and rule-service tests green, checkstyle clean on every touched module, RAT clean.