javaundertowjboss-toolsjboss-eap-7jboss-developer-studio

Java Websockets client Undertow's BasicWebSocketSessionRemoteEndpoint sendBinary throws BufferOverflowException


I have the following code snippet that taken from my websocket client:

byte[] message = "test".getBytes();
session.getBasicRemote().sendBinary(ByteBuffer.wrap(message));

session is UndertowSession and getBasicRemote() returns BasicWebSocketSessionRemoteEndpoint object.

When calling sendBinary() the method throws BufferOverflowException with the following stack trace:

java.nio.BufferOverflowException
    at java.nio.Buffer.nextPutIndex(Buffer.java:521)
    at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:297)
    at io.undertow.websockets.core.protocol.version07.WebSocket07FrameSinkChannel.createFrameHeader(WebSocket07FrameSinkChannel.java:129)
    at io.undertow.server.protocol.framed.AbstractFramedStreamSinkChannel.getFrameHeader(AbstractFramedStreamSinkChannel.java:143)
    at io.undertow.server.protocol.framed.AbstractFramedChannel.flushSenders(AbstractFramedChannel.java:623)
    at io.undertow.server.protocol.framed.AbstractFramedChannel.flush(AbstractFramedChannel.java:715)
    at io.undertow.server.protocol.framed.AbstractFramedChannel.queueFrame(AbstractFramedChannel.java:708)
    at io.undertow.server.protocol.framed.AbstractFramedStreamSinkChannel.queueFinalFrame(AbstractFramedStreamSinkChannel.java:257)
    at io.undertow.server.protocol.framed.AbstractFramedStreamSinkChannel.shutdownWrites(AbstractFramedStreamSinkChannel.java:242)
    at io.undertow.websockets.core.WebSockets.sendBlockingInternal(WebSockets.java:468)
    at io.undertow.websockets.core.WebSockets.sendBinaryBlocking(WebSockets.java:288)
    at io.undertow.websockets.jsr.WebSocketSessionRemoteEndpoint$BasicWebSocketSessionRemoteEndpoint.sendBinary(WebSocketSessionRemoteEndpoint.java:267)
    at myproject.core.server.utils.websocket.messagehandler.EchoStreamMessageHandler.onMessage(EchoStreamMessageHandler.java:49)
    at myproject.core.server.utils.websocket.messagehandler.EchoStreamMessageHandler.onMessage(EchoStreamMessageHandler.java:12)
    at io.undertow.websockets.jsr.FrameHandler$6.run(FrameHandler.java:248)
    at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)
    at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:542)
    at io.undertow.websockets.jsr.FrameHandler.invokeBinaryHandler(FrameHandler.java:216)
    at io.undertow.websockets.jsr.FrameHandler.onFullBinaryMessage(FrameHandler.java:329)
    at io.undertow.websockets.core.AbstractReceiveListener$1.complete(AbstractReceiveListener.java:130)
    at io.undertow.websockets.core.AbstractReceiveListener$1.complete(AbstractReceiveListener.java:124)
    at io.undertow.websockets.core.BufferedBinaryMessage$1.handleEvent(BufferedBinaryMessage.java:113)
    at io.undertow.websockets.core.BufferedBinaryMessage$1.handleEvent(BufferedBinaryMessage.java:98)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel$1.run(AbstractFramedStreamSourceChannel.java:273)
    at io.undertow.server.protocol.framed.AbstractFramedChannel$3.run(AbstractFramedChannel.java:232)
    at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:580)
    at org.xnio.nio.WorkerThread.run(WorkerThread.java:464)

I also tried to call sendBinary with allocated ByteBuffer:

ByteBuffer buff = ByteBuffer.allocate(message.length);
buff.put(message);
buff.flip();
this.session.getBasicRemote().sendBinary(buff);

But got the same exception.

Any ideas how to resolve this?

Thanks!

Eldad


Solution

  • Ok, Figured this out:

    Other parts of my code changed Undertow's web socket buffer size to a very small number.