question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with WebSocket transport compression for RSocket

See original GitHub issue

Unable to make WebSocket transport compression work in RSocket client/server Spring Boot applications running with Netty backend and Spring Boot version 2.5.9.

The Spring Boot allows to specify the server-side RSocket transport and endpoint path in the application.properties, but there are no any additional configuration parameters available besides that. The autoconfig creates an instance of the RSocketWebSocketNettyRouteProvider which doesn’t have compression enabled and also doesn’t have any customizers to enable it.

To get around that I removed spring.rsocket.server.mapping-path property and declared a bean like this in the server config to pass a WebsocketServerSpec with compress option enabled to httpServerRoutes.ws(...) call:

    @Bean
    NettyRouteProvider rSocketWebsocketRouteProvider(
            RSocketProperties properties, RSocketMessageHandler messageHandler,
            ObjectProvider<RSocketServerCustomizer> customizers) {
        return new NettyRouteProvider() {
            public HttpServerRoutes apply(HttpServerRoutes httpServerRoutes) {
                RSocketServer server = RSocketServer.create(messageHandler.responder());
                customizers.forEach((customizer) -> customizer.customize(server));

                return httpServerRoutes.ws("/rsocket",
                        WebsocketRouteTransport.newHandler(server.asConnectionAcceptor()),
                        WebsocketServerSpec.builder().compress(true).build());
            }
        };
    }

On the client side I’m creating RSocketRequester like this:

RSocketRequester requester = builder
                .setupRoute("/backend/connect")
                .setupData(id)
                .rsocketConnector(connector -> connector
                        .reconnect(Retry.fixedDelay(Integer.MAX_VALUE, Duration.ofSeconds(5)))
                        .acceptor(RSocketMessageHandler.responder(strategies, backendController)) // ****** (1)
                )
                .dataMimeType(MediaType.APPLICATION_JSON)
                .transport(() -> {
                    // httpClient is immutable - baseUrl() creates a copy
                    ClientTransport t = WebsocketClientTransport.create(
                                HttpClient.create().baseUrl(backendUrl), "/rsocket")
                            .webSocketSpec(configurer -> configurer
                                    .compress(true) // ****** (2)
                                    .maxFramePayloadLength(65536));
                    return t.connect();
                });

The webSocketSpec need to have compress flag enabled. Otherwise I don’t see compression applied when looking at the traffic in Charles proxy with a simple port forwarding enabled.

The problem is that when compress is enabled on line (2) the client can’t complete the connection sequence. However if I comment out the .acceptor() configuration on line (1) the connect is working and I see server to client calls going through and I can see data is being compressed. But without the acceptor server can’t call the client.

Here is an example project repository https://github.com/maximdim/rsocket2/tree/rsocket-compression You can launch BackendApplication and AgentApplication to observe described issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rstoyanchevcommented, Mar 28, 2022

@ekuleshov apologies for the delay. I have been able to reproduce this and the issue seems to be related to the client acceptor not being able to read anything from the SETUP payload. This is for any client acceptor, and it’s reproducible with just RSocket Java. I’ve created https://github.com/rsocket/rsocket-java/issues/1045 to supersede this one.

Thanks for the report!

1reaction
ekuleshovcommented, Feb 7, 2022

As far as I can see, this is all within the RSocketServerAutoConfiguration. There is no server transport initialization in the Spring Framework. @philwebb now that you’ve created spring-projects/spring-boot#29550, is there is any reason to still keep this issue open?

Please see my rSocketWebsocketRouteProvider() bean override that enables server-side compression. But with that stuff enabled I was unable to confirm compression working between client and server.

The #29550 issue is about removing the need in such override and allowing to configure server-side compression with autoconfig, server properties, etc… But the compression either does not work or my configuration change is not correct one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with WebSocket transport compression for RSocket
Unable to make WebSocket transport compression work in RSocket client/server Spring Boot applications running with Netty backend and Spring ...
Read more >
How to enable websocket message compression deflate (with ...
How to support WebSocket transport with Spring Boot RSocket server? 1 · WebSocket cannot connect to endpoint when running Spring-Boot 2.2 with ...
Read more >
Compression Extensions for WebSocket RFC 7692
This framework provides a general method for applying a compression algorithm to the contents of WebSocket messages. Each compression algorithm has to be ......
Read more >
Scaling Socket.IO - practical considerations - Ably Realtime
"The Socket.IO server currently has some problems with scaling up to more than 10K simultaneous client connections when using multiple processes ...
Read more >
Deep Dive into WebSockets - Bits and Pieces
A common issue when working with WebSockets is broken connections. This occurs when either the client or server does not respond. To avoid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found