Skip to content

WebSocket compression support is broken #413

Description

@robert-s-ubi

Unfortunately, the recently added WebSocket compression support is broken due to a bug in the Java-WebSocket library (TooTallNate/Java-WebSocket#1496).

If WebSocket compression is enabled on a MultiProtocolJSONClient, the second message exchange with the MultiProtocolJSONServer yields an exception:

org.java_websocket.exceptions.InvalidDataException: invalid distance too far back
at org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension.decodeFrame(PerMessageDeflateExtension.java:193)
at org.java_websocket.drafts.Draft_6455.translateSingleFrame(Draft_6455.java:589)
at org.java_websocket.drafts.Draft_6455.translateFrame(Draft_6455.java:762)
at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:394)
at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:229)

This can be worked around by changing the PerMessageDeflation configuration in MultiProtocolJSONClient perMessageDeflateExtension.setServerNoContextTakeover(false -> true), but that yields a much lower compression efficiency.

Activity

robert-s-ubi commented on Dec 19, 2025

@robert-s-ubi
ContributorAuthor

I have submitted a PR to the Java-WebSocket library to fix the issue on their end:

TooTallNate/Java-WebSocket#1497

I don't know if or when this PR will be picked up, and when that might be released. In the meantime, if you want to use WebSocket compression, you can either compile this library from source with the modification mentioned above, or compile the Java-WebSocket library from source with the above PR patched in and use this library unmodified. The latter solution yields much higher compression efficiency (at the cost of higher memory usage).

robert-s-ubi commented on Dec 24, 2025

@robert-s-ubi
ContributorAuthor

The fix above is actually not enough, so I wrote a new implementation from scratch, which is available as a PR here:

#414

I will also contribute this to the Java-WebSocket project, but them picking it up and making a bugfixed release might take a while.

robert-s-ubi commented on Dec 24, 2025

@robert-s-ubi
ContributorAuthor

Note that the MultiProtocolJSONServer from release 2.0 enables WebSocket compression by default using the buggy Java-WebSocket implementation, which WILL cause problems with clients supporting WebSocket compression as well.

As a workaround, disable WebSocket compression by passing a JSONConfiguration object to MultiProtocolJSONServer created like this:

JSONConfiguration.get().setParameter(JSONConfiguration.WEBSOCKET_COMPRESSION_SUPPORT, false);

In MultiProtocolJSONClient, the default is disabled, so unless you are explicitly enabling it, there is no precaution to take.

robert-s-ubi commented on Mar 31, 2026

@robert-s-ubi
ContributorAuthor

The PR to fix this has been merged, but there is no release with this fix yet. Build the current master to get a fixed version.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions