Skip to content

fix: keep push connections open while the service is starting - #25485

Open
mcollovati wants to merge 1 commit into
mainfrom
issues/25482-push-connect-when-service-ready
Open

fix: keep push connections open while the service is starting#25485
mcollovati wants to merge 1 commit into
mainfrom
issues/25482-push-connect-when-service-ready

Conversation

@mcollovati

Copy link
Copy Markdown
Collaborator

The push endpoint can be reached before the Vaadin service has finished starting. A browser tab that keeps retrying its connection, for example one left open across a server restart, could therefore connect too early and the connection failed with an error.

Such a connection is now held until startup finishes and is then handled as usual. Closing it instead would make the browser fall back to a slower connection type for the rest of the page's life. The connection is closed only if startup fails, and is dropped if the browser gives up while waiting.

Fixes #25482

@mcollovati

Copy link
Copy Markdown
Collaborator Author

If we plan to backport to other 25 and 24 branches, it will need manual pick because of the new test module.
For 24.x it also needs the JUnit 5 to 4 migration

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Push connect/message now waits for the service instead of running immediately

flowchart LR
    subgraph Before
        direction TB
        B1["onConnect / onMessage"] -->|runs immediately| B2["doOnConnect (uses service)"]
        B2 -.->|service still starting| B3["connection fails"]
    end
    subgraph After
        direction TB
        A1["onConnect / onMessage"] -->|deferUntilServiceReady| A2{"service.isInitialized()?"}
        A2 -->|yes| A3["doOnConnect"]
        A2 -->|"no (new)"| A4["suspend(resource) + whenInitialized()"]:::changed
        A4 -->|init ok| A3
        A4 -->|init failed| A5["closeResource()"]:::changed
        A4 -.->|client gave up| A6["drop"]
    end
    Before ~~~ After
    classDef changed stroke:#c9a227,stroke-width:3px
Loading

PushHandler.onConnect/onMessage now route through the new deferUntilServiceReady, which checks VaadinService.isInitialized(). When the service is still starting it suspends the resource and registers VaadinService.whenInitialized (backed by a new initCompleted CompletableFuture); on completion it runs the held action, calls closeResource if init failed, or drops the request if the client already disconnected. Previously the handler ran doOnConnect right away and the early connection failed, per the PR description and #25482. The highlighted nodes are the deferral path this PR adds.

Diagram Bot draws the mechanism this pull request touches; it does not review the change. Verify it against the diff.

Generated by Diagram Bot for issue #25485 ·

@github-actions github-actions Bot added the +0.0.1 label Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Test Results

 1 435 files  +1   1 519 suites  +1   1h 45m 49s ⏱️ + 10m 29s
11 878 tests ±0  11 811 ✅ +1  67 💤  - 1  0 ❌ ±0 
12 197 runs  +1  12 129 ✅ +1  68 💤 ±0  0 ❌ ±0 

Results for commit 31249ce. ± Comparison against base commit 233f545.

♻️ This comment has been updated with latest results.

@mcollovati
mcollovati force-pushed the issues/25482-push-connect-when-service-ready branch 2 times, most recently from ecdcced to 54d17f7 Compare September 4, 2026 17:58
The push endpoint can be reached before the Vaadin service has finished
starting. A browser tab that keeps retrying its connection, for example
one left open across a server restart, could therefore connect too early
and the connection failed with an error.

Such a connection is now held until startup finishes and is then handled
as usual. Closing it instead would make the browser fall back to a slower
connection type for the rest of the page's life. The connection is closed
only if startup fails, and is dropped if the browser gives up while
waiting.

Fixes #25482
@mcollovati
mcollovati force-pushed the issues/25482-push-connect-when-service-ready branch from 54d17f7 to 31249ce Compare September 4, 2026 18:12
@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push websocket connecting during startup throws "Can not process requests before init() has been called"

1 participant