Skip to content

[ISSUE #8429] Bridge Spring application readiness and shutdown to the instance serving state - #8546

Open
konlue wants to merge 2 commits into
apache:masterfrom
konlue:feat/8429-readiness-bridge
Open

konlue wants to merge 2 commits into
apache:masterfrom
konlue:feat/8429-readiness-bridge

Conversation

@konlue

@konlue konlue commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #8429.

The Java client's registration is asynchronous and its serving-state SPI (ready/notReady/draining from the accepted #8042 contract) has zero callers on the client side: URI registration gates only on a TCP connect — not application readiness — and the first serving-state signal at shutdown is the JVM-hook offline, so a Spring application that temporarily refuses traffic or starts a graceful shutdown never tells the gateways anything until the process exits. This PR adds the bridge as a thin, opt-in adapter over that existing contract; it redefines neither readiness propagation nor drain semantics.

What changed

ServingStateLifecycleBridge (in the common client starter) listens to Spring readiness and emits the repository calls at real state transitions only: ApplicationReadyEvent/ACCEPTING_TRAFFIC emits ready (releasing a previous refusal), REFUSING_TRAFFIC emits notReady — refusing new work while staying alive, never degrading into an offline — and repeated identical Spring events emit nothing (an explicit INIT → READY → NOT_READY → READY → DRAINING state machine guards idempotency). At context close — which fires before the web server's graceful shutdown and the JVM hooks — the bridge stops heartbeat renewal first so no renewal races the drain, then requests draining for exactly the URIs the registration flow registered; draining is terminal, in-flight request draining and the final offline stay with the web server lifecycle and the existing JVM hooks, and heartbeats can never clear a drain because the Admin-side props markers from #8042 are untouched. Updates pass the registered URIRegisterDTOs through unchanged so namespace/protocol/identity binding stays intact, per-identity failures are logged without blocking shutdown and never become an offline, and repositories without the capability keep their default no-ops.

The client-side change is deliberately tiny: the URI subscriber exposes a read-only snapshot of its registered identities and the publisher exposes the subscriber accessor. The bridge is opt-in via shenyu.register.lifecycle-bridge.enabled=true (registered through @AutoConfiguration with @ConditionalOnBean(ShenyuClientRegisterRepository.class)), so shipped behavior changes nothing by default and a missing property or repository leaves no bridge bean behind.

Tests

ServingStateLifecycleBridgeTest drives the state machine against a mock repository: ready emits for every registered identity, REFUSING_TRAFFIC emits not-ready and never offline, ACCEPTING_TRAFFIC again releases the refusal, repeated ready events are idempotent, not-ready before any readiness emits nothing, context close stops renewal exactly once and then drains while the JVM stays alive (draining is terminal and later readiness changes emit nothing), repeated close events drain exactly once, a failing draining never blocks shutdown or becomes an offline, identity fields pass through unchanged, and the opt-in configuration registers the bridge only when both the property and a repository exist. The subscriber snapshot test pins the read-only, registration-independent view. All lifecycle assertions are red against a subscriber that cannot expose identities. Module results on the current master baseline: shenyu-client-core 106 (was 102) and shenyu-spring-boot-starter-client-common 14 (was 4) — all green; checkstyle clean.

…to the instance serving state

ServingStateLifecycleBridge (opt-in, shenyu.register.lifecycle-bridge.enabled=true) listens to ApplicationReadyEvent and AvailabilityChangeEvent and emits repository ready/notReady at real state transitions only: repeated Spring events are idempotent, REFUSING_TRAFFIC refuses new work while staying alive and never degrades into an offline, and ACCEPTING_TRAFFIC releases a previous refusal. At context close — which precedes the web server's graceful shutdown and the JVM hooks — the bridge stops heartbeat renewal first, then requests draining for exactly the URIs the registration flow registered, passed through unchanged so namespace/protocol/identity binding stays intact; a failing update is logged without blocking shutdown, draining is terminal, and repositories without the capability keep their default no-ops while heartbeats can never clear a drain (the Admin-side apache#8042 markers are untouched). Client-side changes are two read-only seams (a registered-URI snapshot and a publisher accessor), keeping the whole thing a thin adapter over the accepted contract. Tests drive ready/not-ready/ready sequences, idempotency, context close while the JVM stays alive, failure tolerance, identity pass-through and the opt-in gating, red against a subscriber that cannot expose identities.
…pository bean

The bridge's @ConditionalOnBean(ShenyuClientRegisterRepository) relied on the implicit order of the imports file; the after clause makes the dependency explicit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task][Java Client] Bridge Spring application readiness and shutdown to business-instance serving state

1 participant