Skip to content

fix: prevent deadlock on concurrent push and disconnect (2.13)#24214

Merged
mshabarov merged 1 commit into2.13from
feature/pushconnection-deadlock
Apr 30, 2026
Merged

fix: prevent deadlock on concurrent push and disconnect (2.13)#24214
mshabarov merged 1 commit into2.13from
feature/pushconnection-deadlock

Conversation

@mcollovati
Copy link
Copy Markdown
Collaborator

The previous AtomicBoolean guard in AtmospherePushConnection closed only the disconnect-vs-disconnect race. A push thread that reads disconnecting as false before a concurrent disconnect() flips it can still proceed into synchronized(lock) behind the disconnect thread, which is itself blocked inside resource.close() waiting for the servlet container's HTTP session lock held by the push thread — a two-lock cycle.

Move resource.close() out of the monitor: inside synchronized(lock) capture the resource into a local and call connectionLost() to transition the state, then release the monitor before invoking close() on the stashed reference. Add a matching re-check of isConnected() at the top of the synchronized block in push() so a push that waited for the monitor observes the late disconnect and defers via PUSH_PENDING/RESPONSE_PENDING instead of NPEing on the cleared resource. The disconnecting flag stays set until close() returns so subsequent pushes take the fast path and no new disconnect() re-enters while close() is still in flight.

Related-to #24192

The previous `AtomicBoolean` guard in `AtmospherePushConnection`
closed only the disconnect-vs-disconnect race. A push thread that
reads `disconnecting` as false before a concurrent `disconnect()`
flips it can still proceed into `synchronized(lock)` behind the
disconnect thread, which is itself blocked inside `resource.close()`
waiting for the servlet container's HTTP session lock held by the
push thread — a two-lock cycle.

Move `resource.close()` out of the monitor: inside
`synchronized(lock)` capture the resource into a local and call
`connectionLost()` to transition the state, then release the monitor
before invoking `close()` on the stashed reference. Add a matching
re-check of `isConnected()` at the top of the `synchronized` block
in `push()` so a push that waited for the monitor observes the late
disconnect and defers via `PUSH_PENDING`/`RESPONSE_PENDING` instead
of NPEing on the cleared resource. The `disconnecting` flag stays
set until `close()` returns so subsequent pushes take the fast path
and no new `disconnect()` re-enters while `close()` is still in
flight.

Related-to #24192
@sonarqubecloud
Copy link
Copy Markdown

@mshabarov mshabarov merged commit 87526fc into 2.13 Apr 30, 2026
8 checks passed
@mshabarov mshabarov deleted the feature/pushconnection-deadlock branch April 30, 2026 11:31
@vaadin-bot
Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 14.14.3.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants