spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

setting max frame size on websockets

Open saiyedzaidi opened this issue 8 years ago • 17 comments

This is a question to verify my understanding.

I find the value for maximum frame size hard coded into ReactorNettyWebSocketSession org.springframework.web.reactive.socket.adapter.ReactorNettyWebSocketSession.receive() and other classes use this class by creating new instances, leaving very cumbersome way of overriding beans to configure the frame size value. I have got it to work by overriding the ReactorNettyWebSocketSession bean and redeclaring it. I thunk it will need code updates within the spring cloud gateway code base to allow picking up the value from configuration in a simpler manner.

saiyedzaidi avatar Jan 16 '18 11:01 saiyedzaidi

Can you explain more what you did? I can't find a bean declaration of ReactorNettyWebSocketSession anywhere.

spencergibb avatar Jan 16 '18 18:01 spencergibb

GatewayAutoConfiguration.websocketRoutingFilter declares the filter bean reactorNettyWebSocketClient() creates the client bean, webSocketService() too.

ReactorNettyWebSocketClient has new ReactorNettyWebSocketSession(in, out, info, factory) hardcoded. ReactorNettyRequestUpgradeStrategy has new ReactorNettyWebSocketSession(in, out, info, bufferFactory) hardcoded.

I had to extend these two classes to allow the frame size value be set and then create new instance of webroutingfilter with these custom beans.

On the source, I think 1. there should be a a common wesbockets properties. 2. have these classes check them for config before falling back to defaults.

saiyedzaidi avatar Jan 17 '18 07:01 saiyedzaidi

I'm still confused about what you think the gateway should do. All of those classes are from reactor netty. I have no plans to extend either one. If you think they need to be configurable, open an issue in reactor-netty and then maybe we can take advantage of it.

spencergibb avatar Jan 30 '18 00:01 spencergibb

I also found the value for maximum frame size hard coded. When I am using ReactorNettyWebSocketClient is there any way to configure that value? Would be hard to do it like the way @saiyedzaidi mentioned.

manuel-armbruster avatar Feb 20 '18 21:02 manuel-armbruster

@saiyedzaidi @tonyskulk I think you'll need to open an issue with spring-framework to allow setting a value. @rstoyanchev thoughts?

spencergibb avatar Feb 20 '18 22:02 spencergibb

@saiyedzaidi I suspect you're referring to this but that's size for aggregateFrames feature of Reactor Netty, and it doesn't change the underlying max frame size in Netty. We have a ticket to make that configurable in the Spring Framework but it depends on Reactor Netty exposing the property in the first place.

rstoyanchev avatar Feb 21 '18 00:02 rstoyanchev

Thanks @rstoyanchev. I'm watching the framework ticket and https://github.com/reactor/reactor-netty/issues/223. This will be on hold until then.

spencergibb avatar Feb 21 '18 00:02 spencergibb

Thanks @spencergibb and @rstoyanchev. I am watching both tickets, too.

manuel-armbruster avatar Feb 21 '18 22:02 manuel-armbruster

I found that the problem is fixed by SpringBoot 2.1.0.RELEASE and Greenwich.M2. But I don't know how to set max frame size on websockets? Can anyone help? Thanks very much.

zyliu1985 avatar Nov 22 '18 09:11 zyliu1985

Hi @spencergibb , Did this issue have fixed and milestone? Thank you.

zyliu1985 avatar Nov 23 '18 08:11 zyliu1985

This is now dependent on https://github.com/spring-projects/spring-framework/pull/22328

spencergibb avatar Jan 31 '19 19:01 spencergibb

See https://github.com/spring-projects/spring-framework/pull/22367

spencergibb avatar Mar 19 '19 15:03 spencergibb

I tried the milestone builds. In ReactorNettyWebSocketClient the property is correctly set from the application properties.

But in ReactorNettyRequestUpgradeStrategy the value is not set. GatewayAutoConfiguration initiates the HandshakeWebSocketService (in Bean "webSocketService") without constructor parameter UpgradeStrategy. (@saiyedzaidi mentioned this, too)

I had to extend GatewayAutoConfiguration's bean webSocketService, instantiate a new ReactorNettyUpgradeStrategy, set MaxFramePayloadLength in there and pass it to the HandshakeWebSocketService constructor.

Shouldn't that be part of the fix, too? Thank you

yves1982 avatar Aug 20 '19 06:08 yves1982

I tried the milestone builds. In ReactorNettyWebSocketClient the property is correctly set from the application properties.

But in ReactorNettyRequestUpgradeStrategy the value is not set. GatewayAutoConfiguration initiates the HandshakeWebSocketService (in Bean "webSocketService") without constructor parameter UpgradeStrategy. (@saiyedzaidi mentioned this, too)

I had to extend GatewayAutoConfiguration's bean webSocketService, instantiate a new ReactorNettyUpgradeStrategy, set MaxFramePayloadLength in there and pass it to the HandshakeWebSocketService constructor.

Shouldn't that be part of the fix, too? Thank you

Hi, could you explain how to extend GatewayAutoConfiguration?

dkej123 avatar Oct 02 '19 16:10 dkej123

@dkwasniak can you please open a new issue with how to recreate the problem?

spencergibb avatar Oct 02 '19 16:10 spencergibb

@dkwasniak

@Configuration
@Import(GatewayAutoConfiguration.class)
public class CustomGatewayAutoConfiguration extends GatewayAutoConfiguration {
    public CustomGatewayAutoConfiguration() {
    }

    @Override
    @Bean
    public WebSocketService webSocketService() {

        ReactorNettyRequestUpgradeStrategy reactorNettyRequestUpgradeStrategy = new ReactorNettyRequestUpgradeStrategy();
        reactorNettyRequestUpgradeStrategy.setMaxFramePayloadLength(10485760);

        return new HandshakeWebSocketService(reactorNettyRequestUpgradeStrategy);
    }
}

yves1982 avatar Oct 15 '19 08:10 yves1982

The original issue was for the WebSocketClient created in GatewaAutoConfiguraiton while @yves1982 is raising the same point but for the server side WebSocketService in the same configuration which should be created with a customized RequestUpgradeStrategy as the code snippet above shows.

@yves1982 it's probably best to create a new issue indeed as this one is already tied to a fix that has been released.

rstoyanchev avatar Oct 15 '19 13:10 rstoyanchev