jetty / jetty/jetty.project

Serialize calls to the WebSocket Core FrameHandler

Open
#9,892 3 comments 0 reactions 1 assignee Claimed by @lachlan-roberts View on GitHub
Bug
Dominant language
Java
Stars
4.1k
Forks
2k
Avg merge
3d 56m
Merged PRs (30d)
48

Description

**Jetty version(s)**
10+

**Description**
Currently there is no protection against the `FrameHandler` being invoked concurrently by multiple threads.

In particular during an idleTimeout event, even if a FrameHandler is currently in `onOpen()` or `onMessage()` then the idleTimeout could occur and the `onClosed` notification would be called concurrently.

the jakarta websocket 2.1 specification states:
> In all cases, the implementation must not invoke an endpoint instance with more than one thread per peer at a time [WSC-5.1-2]. The implementation may not invoke the close method on an endpoint until after the open method has completed [WSC-5.1-3].
>
> This guarantees that a WebSocket endpoint instance is never called by more than one container thread at a time per peer [WSC-5.1-4].

Currently this is not the case as `onClosed()` can be called concurrently to `onOpen()` and `onMessage()`. But if we serialized the notifications to the `FrameHandler` in core it would solve this issue.

The `FrameHandler` implementations are currently not taking this into consideration, so are not protecting fields in a lock that could be modified concurrently by `onMessage` and `onClosed`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.