how to increase frame size of websocket

5,520 views
Skip to first unread message

Shameet Doshi

unread,
Aug 22, 2013, 4:11:28 PM8/22/13
to ve...@googlegroups.com
Hi

I am using Vertx for websockets. I got the below error while sending a big message. 

io.netty.handler.codec.CorruptedFrameException: Max frame length of 65536 has been exceeded.
        at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:409)
        at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.decode(WebSocket08FrameDecoder.java:236)
        at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:360)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:131)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:372)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:357)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:780)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:99)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:497)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:465)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:359)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
        at java.lang.Thread.run(Thread.java:724)

found that DefaultHttpServer while instantiating WebSocketServerHandshakerFactory doesnt allow configuring of the framesize and hence gets set to default 65536. Is there a way I can get around this problem ?


 factory = new WebSocketServerHandshakerFactory(getWebSocketLocation(ch.pipeline(), request), null, false);


  public WebSocketServerHandshakerFactory(
            String webSocketURL, String subprotocols, boolean allowExtensions) {
        this(webSocketURL, subprotocols, allowExtensions, 65536);
    }

thanks

shameet 

Stream

unread,
Aug 22, 2013, 9:42:37 PM8/22/13
to ve...@googlegroups.com

turn your parameter of web socket

setReceiveBufferSize(bigger than 65536)
setSendBufferSize (bigger than 65536)

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Shameet Doshi

unread,
Aug 23, 2013, 8:11:03 AM8/23/13
to ve...@googlegroups.com
i had tried that but didnt work

the WebSocket08FrameDecoder gets the maxFramePayloadLength from WebSocketServerHandshakerFactory which the DefaultHttpServer  instantiates using the constructor where it doesn't pass any maxFramePayloadLength

 factory = new WebSocketServerHandshakerFactory(getWebSocketLocation(ch.pipeline(), request), null, false);


  public WebSocketServerHandshakerFactory(
            String webSocketURL, String subprotocols, boolean allowExtensions) {
        this(webSocketURL, subprotocols, allowExtensions, 65536);
    }


public WebSocket08FrameDecoder(boolean maskedPayload, boolean allowExtensions, int maxFramePayloadLength) {
        super(State.FRAME_START);
        this.maskedPayload = maskedPayload;
        this.allowExtensions = allowExtensions;
        this.maxFramePayloadLength = maxFramePayloadLength;

Norman Maurer

unread,
Aug 23, 2013, 8:18:04 AM8/23/13
to ve...@googlegroups.com
It's currently not supported… Could you please open an issue in our bugzilla ?

Shameet Doshi

unread,
Aug 23, 2013, 10:57:01 AM8/23/13
to ve...@googlegroups.com
created https://bugs.eclipse.org/bugs/show_bug.cgi?id=415769 for this. 

thanks

shameet


--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/TDpCFM6LuaI/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to vertx+un...@googlegroups.com.

Shameet Doshi

unread,
Sep 24, 2013, 11:07:11 AM9/24/13
to ve...@googlegroups.com, norman...@googlemail.com
Hi Norman

I have made the following changes for my project to increase the framesize

HttpServer.java




   /**
    * Set the max frame size
    * @return a reference to this so multiple method calls can be chained together
    */
  HttpServer setMaxFramePayloadLength(int maxFramePayloadLength);


   /**
    *
    * @return The max frame size
    */
   int getMaxFramePayloadLength();


------------


DefaultHttpServer.java

private int maxFramePayloadLength = 65536;

 @Override
  public HttpServer setMaxFramePayloadLength(int maxFramePayloadLength){
     this.maxFramePayloadLength = maxFramePayloadLength;
     return this;
  }
  @Override
  public int getMaxFramePayloadLength(){
      return maxFramePayloadLength;
  }


  private void handshake(final FullHttpRequest request, final Channel ch, ChannelHandlerContext ctx) throws Exception {
      final WebSocketServerHandshaker shake;
  ---->   WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(getWebSocketLocation(ch.pipeline(), request), null, false, getMaxFramePayloadLength());
     


---------------

Usage in vertx

HttpServer server = vertx.createHttpServer();
server.setMaxFramePayloadLength(2097152);



Shameet 

Sidney Hudgens

unread,
May 5, 2014, 12:54:52 AM5/5/14
to ve...@googlegroups.com, norman...@googlemail.com
Hi shameet,

I am stuck on the exact same error and I don't understand the solution described.
Is this a bug or can I set a parameter to bypass the default limit ?
I saw those parameters setsendbuffersize and setreceivebuffersize but they doesn't seem to work well.

Any help on that topic ?

Thanks,

Sid

Norman Maurer

unread,
May 5, 2014, 1:00:18 AM5/5/14
to ve...@googlegroups.com, Sidney Hudgens
Not sure I understand your problem… Just increase the size with setMaxFramePayloadLength and it should work.

-- 
Norman Maurer

Sidney Hudgens

unread,
May 5, 2014, 9:18:19 AM5/5/14
to ve...@googlegroups.com, Sidney Hudgens, norman...@googlemail.com
thanks for your answer.

My problem is this one :

io.netty.handler.codec.CorruptedFrameException: Max frame length of 65536 has been exceeded.
        at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:409)
        at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.decode(WebSocket08FrameDecoder.java:236)
        at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:360)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:131)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:372)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:357)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:780)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:99)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:497)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:465)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:359)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
        at java.lang.Thread.run(Thread.java:724)

Then I am trying to use the .setMaxFramePayloadLength() I got this compilation error :

sockJSServer.setMaxFramePayloadLength(2097152);

                ^

  symbol:   method setMaxFramePayloadLength(int)

  location: variable sockJSServer of type org.vertx.java.core.sockjs.SockJSServer 

Exception in JavaScript verticle 

java.lang.RuntimeException: Compilation failed

at org.vertx.java.platform.impl.java.CompilingClassLoader.<init>(CompilingClassLoader.java:108)

at org.vertx.java.platform.impl.java.JavaVerticleFactory.createVerticle(JavaVerticleFactory.java:51)

at org.vertx.java.platform.impl.DefaultPlatformManager$21.run(DefaultPlatformManager.java:1723)

at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:175)

at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)

at java.lang.Thread.run(Thread.java:744)

Caused by: java.lang.RuntimeException: Compilation failed!

Sorry I am new to Java, and I didn't find a way to increase the frame size with Javascript.

Norman Maurer

unread,
May 5, 2014, 10:23:39 AM5/5/14
to ve...@googlegroups.com, Sidney Hudgens, Sidney Hudgens
It is not allowed to send bigger frames by the spec. You will need to send frames that are split.

-- 
Norman Maurer

Cristián Serpell

unread,
May 5, 2015, 5:15:17 PM5/5/15
to ve...@googlegroups.com, hudge...@gmail.com, norman...@googlemail.com
Hi, I am facing the same problem, but I am not sure I can modify base HttpServer code for my project. Is there any other workaround? I would really want to fix this without having to split my server calls.

Thanks

Ayhan Ergul

unread,
May 5, 2015, 11:48:10 PM5/5/15
to ve...@googlegroups.com
Hi Cristián,

Since vertx 2.1, HttpServer does provide a way to change the max frame size:

    HttpServer server = vertx.createHttpServer();
    server.setMaxWebSocketFrameSize(new_frame_size);

I originally ran into the CorruptedFrameException while using mod-web-server, so I modified it to support a configuration parameter for the maximum frame size. I put that on github if you want to take a look: https://github.com/aergul/mod-web-server/commit/5b62cc0d43b101de5ccaca62c68e1b549442e7e9


Ayhan

Tim Fox

unread,
May 6, 2015, 3:25:30 AM5/6/15
to ve...@googlegroups.com
Which version of Vert.x are you using?


On 05/05/15 22:15, Cristián Serpell wrote:
Hi, I am facing the same problem, but I am not sure I can modify base HttpServer code for my project. Is there any other workaround? I would really want to fix this without having to split my server calls.

Thanks
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cristián Serpell

unread,
May 6, 2015, 9:52:03 AM5/6/15
to ve...@googlegroups.com
Interesting. So that's why help in the forum didn't work. I am using vertx 2.0.2. I finally managed to fix my issue separating the call in many different calls, but I appreciate this. I will see if upgrading doesn't break us so I can change the frame size.

Reply all
Reply to author
Forward
0 new messages