Skip to content

fix(WebSocket): send STOMP heartbeats from the simple broker - #366

Open
Isaries wants to merge 1 commit into
WISE-Community:developfrom
Isaries:fix/stomp-heartbeat
Open

Isaries wants to merge 1 commit into
WISE-Community:developfrom
Isaries:fix/stomp-heartbeat

Conversation

@Isaries

@Isaries Isaries commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

The simple broker is enabled without heartbeats, so the CONNECTED frame advertises heart-beat:0,0 and an idle connection carries no traffic at all. A reverse proxy in front of the API closes such a connection once its read timeout passes; with nginx's default proxy_read_timeout an idle Classroom Monitor socket was closed with code 1006 after 60 seconds. The simple broker keeps nothing for a subscriber that is not connected, so student status updates published before the client reconnects are lost.

The broker now sends a heartbeat every 20 seconds and requires none from clients. Requiring client heartbeats was rejected because browsers throttle timers in background tabs to about once a minute, which would get the socket of a teacher who switched tabs closed. The heartbeat task runs on Spring's own messageBrokerTaskScheduler, injected lazily as the Spring reference documentation describes.

Testing: WebSocketConfigTest starts the WebSocket messaging configuration and asserts the broker's heartbeat value and task scheduler. Both tests fail on develop and pass with this change. On a deployment behind nginx the CONNECTED frame read heart-beat:20000,0, heartbeats arrived every 20 seconds, and an idle socket stayed open for 173 seconds.

The simple broker was enabled without heartbeats, so the CONNECTED frame
advertised heart-beat:0,0 and an idle connection carried no traffic. A
reverse proxy in front of the API closes such a connection once its read
timeout passes (60 seconds by default in nginx). The simple broker keeps
nothing for a subscriber that is not connected, so messages published
before the client reconnects are lost, e.g. student status updates in the
Classroom Monitor.

The broker now sends a heartbeat every 20 seconds and requires none from
clients, since browsers throttle timers in background tabs and a required
client heartbeat would get those connections closed. Heartbeats are
scheduled on Spring's own messageBrokerTaskScheduler.
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.

1 participant