Repository navigation
feat: fire service events for resent, resync and out-of-sync messages - #25960
Conversation
Type of change
API changesNew classes in
Usage: service.getEventBus().addListener(UIResynchronizationEvent.class,
event -> resyncCounter.increment()); |
|
Test Results 1 551 files - 15 1 635 suites - 15 1h 40m 31s ⏱️ +13s Results for commit cb537c88. ± Comparison against base commit 253bd55. |
heruan
left a comment
There was a problem hiding this comment.
Looks good. Each event fires only in its own branch of handleRpc (the unload beacon does not trigger MessageIdSyncErrorEvent), and a listener that throws cannot break the resend, sync error or resync handling, because the event bus logs listener errors. This lets Observability Kit drop its second parse of the UIDL body (vaadin/observability-kit#416). No changes needed.
Add a Message Synchronization Events section to the Service Event Bus page covering ClientMessageResentEvent, MessageIdSyncErrorEvent, and UIResynchronizationEvent, fired by ServerRpcHandler. Documents vaadin/flow#25960 (`cb537c88da418bd09b1dcead1e8a2668f6ea9851`).
|
Pull request created: #6204
|
|
Documentation Bot: Draft documentation pull request for this change: vaadin/docs#6204 Files updated:
It was written from the state of this pull request as you see it now. Please review it and mark it ready for review.
|
…#25960) (CP: 25.3) (#26187) This PR cherry-picks changes from the original PR #25960 to branch 25.3. --- #### Original PR description > ## Summary > The server now fires an event on the service event bus in three cases: the client re-sends a message, the client asks for a UI resync, or the client sends a message with an unexpected id. Before, the server only logged these cases. Now apps can react to them, for example to track connection problems. > > ## What changed > - New event classes: `ClientMessageResentEvent`, `UIResynchronizationEvent` and `MessageIdSyncErrorEvent`, all in `com.vaadin.flow.server.communication`. > - `ServerRpcHandler.handleRpc` fires each event through `VaadinService.getEventBus()`. It runs on the request thread while the session is locked. > - `ClientMessageResentEvent` fires before the old response is sent again. > - `MessageIdSyncErrorEvent` fires before `MessageIdSyncException` is thrown. It includes the expected id and the received id. > - `UIResynchronizationEvent` fires before the UI is resynchronized. > - Backward compatible. Only new API is added. Apps that do not listen see no change. > > ## Use case > An operations team wants to see how often users have unstable connections, so they can find network or proxy problems in production. They register listeners at startup and increase metric counters: > > ```java > public class ConnectionMetricsInitListener implements VaadinServiceInitListener { > @OverRide > public void serviceInit(ServiceInitEvent event) { > var bus = event.getSource().getEventBus(); > bus.addListener(UIResynchronizationEvent.class, > e -> metrics.increment("ui.resync")); > bus.addListener(ClientMessageResentEvent.class, > e -> metrics.increment("ui.message.resent")); > bus.addListener(MessageIdSyncErrorEvent.class, > e -> log.warn("Out-of-sync message: expected {}, got {}", > e.getExpectedId(), e.getReceivedId())); > } > } > ``` > > ## API Changes > 3 classes added, 3 constructors added, 5 methods added > > ### com.vaadin.flow.server.communication.ClientMessageResentEvent > > ```java > // Added > public class ClientMessageResentEvent extends EventObject > public ClientMessageResentEvent(UI ui) > public UI getUI() > ``` > > ### com.vaadin.flow.server.communication.MessageIdSyncErrorEvent > > ```java > // Added > public class MessageIdSyncErrorEvent extends EventObject > public MessageIdSyncErrorEvent(UI ui, int expectedId, int receivedId) > public UI getUI() > public int getExpectedId() > public int getReceivedId() > ``` > > ### com.vaadin.flow.server.communication.UIResynchronizationEvent > > ```java > // Added > public class UIResynchronizationEvent extends EventObject > public UIResynchronizationEvent(UI ui) > public UI getUI() > ``` > > ## Test summary > **RPC handling (ServerRpcHandler):** > - Fires one `UIResynchronizationEvent` with the UI on a resync request > - Fires one `ClientMessageResentEvent` with the UI on a duplicate message > - Fires one `MessageIdSyncErrorEvent` with the correct UI, expected id and received id on an unexpected message id > - Not covered: the order of each event compared to the resync or the exception Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
…n#25963) Related to vaadin#25960 **missing API** · flow-server, flow-data · monitoring tools listening to invocation and data events A listener that wants to know how long an RPC invocation, data fetch or count took, whether it failed, or which component an RPC targeted, had to pair the started and ended events in thread locals and look up the component through the internal state tree. The ended events now carry the duration Flow measured, the RPC ended event carries the error, and every RPC event can give the targeted component. **Risks:** -⚠️ Public API: new getters and constructors on existing events. The existing constructors stay and report a zero duration and no error. - ⏱️ Performance: data fetches and counts no longer build events when nothing listens, which is a small saving; timing is only done when a listener is registered. - ✅ No breaking change, no serialization, threading, memory or security impact: the error field is transient like on the failed event. - Added `getDuration()` to `RpcInvocationEndedEvent`, `DataFetchEndedEvent` and `DataCountEndedEvent`, measured from just before the started event - Added `getError()` to `RpcInvocationEndedEvent`, matching `RpcInvocationFailedEvent#getError()` - Data events already report a failure as `-1` rows or count, which is now documented instead of adding a second accessor for it - Added `getComponent()` to `AbstractRpcInvocationEvent`, resolved from the UI's state tree when called, with the same shape as the data events - `DataFetchObserver` runs the query directly when nothing listens to the events of that query - Extended `ServerRpcHandlerTest` and `DataFetchEventsTest` to check the duration, error and component Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
#6204) Documentation for vaadin/flow#25960 by `@totally-not-ai`[bot]. > [!NOTE] > The source pull request is merged, so this documentation describes the final > shape of the change. Please review it and mark it ready for review. **Change categories:** NEW_FEATURE | File | Change | |------|--------| | `articles/flow/advanced/session-lock-and-rpc-listeners.adoc` | Added a Message Synchronization Events section documenting `ClientMessageResentEvent`, `MessageIdSyncErrorEvent`, and `UIResynchronizationEvent`, fired on the service event bus while a client message is handled. Updated the intro paragraph and front matter to mention this new event category. | | `articles/flow/advanced/server-client-communication.adoc` | Corrected what happens when a client message has an unexpected id: the message is discarded and a session synchronization error is shown, rather than a resynchronization being started. | Auto-generated by the Documentation Bot — review before merging. > Generated by [Documentation Bot](https://github.com/vaadin/flow/actions/runs/36560597355) for #25960 · agent · 99.5 AIC · ⌖ 5.62 AIC · ⊞ 11.7K · [◷](https://github.com/search?q=repo%3Avaadin%2Fdocs+%22gh-aw-workflow-id%3A+doc-bot%22&type=pullrequests) > - [x] expires <!-- gh-aw-expires: 2026-10-29T11:22:33.980Z --> on Oct 29, 2026, 11:22 AM UTC <!-- gh-aw-agentic-workflow: Documentation Bot, engine: claude, model: agent, id: 36560597355, workflow_id: doc-bot, run: https://github.com/vaadin/flow/actions/runs/36560597355 --> <!-- gh-aw-expires-type: pull-request --> <!-- gh-aw-workflow-id: doc-bot --> <!-- gh-aw-workflow-call-id: vaadin/flow/doc-bot --> Working on behalf of Petter --------- Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>



Summary
The server now fires an event on the service event bus in three cases: the client re-sends a message, the client asks for a UI resync, or the client sends a message with an unexpected id. Before, the server only logged these cases. Now apps can react to them, for example to track connection problems.
What changed
ClientMessageResentEvent,UIResynchronizationEventandMessageIdSyncErrorEvent, all incom.vaadin.flow.server.communication.ServerRpcHandler.handleRpcfires each event throughVaadinService.getEventBus(). It runs on the request thread while the session is locked.ClientMessageResentEventfires before the old response is sent again.MessageIdSyncErrorEventfires beforeMessageIdSyncExceptionis thrown. It includes the expected id and the received id.UIResynchronizationEventfires before the UI is resynchronized.Use case
An operations team wants to see how often users have unstable connections, so they can find network or proxy problems in production. They register listeners at startup and increase metric counters:
API Changes
3 classes added, 3 constructors added, 5 methods added
com.vaadin.flow.server.communication.ClientMessageResentEvent
com.vaadin.flow.server.communication.MessageIdSyncErrorEvent
com.vaadin.flow.server.communication.UIResynchronizationEvent
Test summary
RPC handling (ServerRpcHandler):
UIResynchronizationEventwith the UI on a resync requestClientMessageResentEventwith the UI on a duplicate messageMessageIdSyncErrorEventwith the correct UI, expected id and received id on an unexpected message id