Skip to content

WebSocket throws exception when client disconnects #7886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wyvx opened this issue Oct 25, 2023 · 0 comments · Fixed by #7890
Closed

WebSocket throws exception when client disconnects #7886

wyvx opened this issue Oct 25, 2023 · 0 comments · Fixed by #7890
Assignees
Labels
4.x Version 4.x websocket WebSocket in Helidon

Comments

@wyvx
Copy link

wyvx commented Oct 25, 2023

I have a simple websocket server. A client can connect and it behaves correctly, until the client disconnects. Then, Helidon throws an Internal Error exception.

Environment Details

  • Helidon Version: 4.0.0
  • Helidon SE or Helidon MP: Helidon SE
  • JDK version: 21
  • OS: macOS Ventura 13.6
  • Docker version (if applicable): None

Problem Description

I have a simple websocket server. I use websocat (https://github.com/vi/websocat) to test as a client. It connects and it behaves correctly, until the client disconnects (Ctrl+C websocat). Then, Helidon throws an Internal Error exception.
This problem is easily reproducible and it happens every time.

This is the stack trace on my program, the server, after I exit the websocket client:

  io.helidon.http.RequestException: Internal error
  io.helidon.http.RequestException$Builder.build(RequestException.java:139)
  io.helidon.webserver.http1.Http1Connection.handle(Http1Connection.java:202)
  io.helidon.webserver.ConnectionHandler.run(ConnectionHandler.java:155)
  io.helidon.common.task.InterruptableTask.call(InterruptableTask.java:47)
  io.helidon.webserver.ThreadPerTaskExecutor$ThreadBoundFuture.run(ThreadPerTaskExecutor.java:239)
  java.base/java.lang.VirtualThread.run(VirtualThread.java:311)
  Cause: io.helidon.common.buffers.DataReader$InsufficientDataAvailableException
  io.helidon.common.buffers.DataReader.pullData(DataReader.java:83)
  io.helidon.common.buffers.DataReader.ensureAvailable(DataReader.java:111)
  io.helidon.common.buffers.DataReader.read(DataReader.java:123)
  io.helidon.websocket.AbstractWsFrame.readFrameHeader(AbstractWsFrame.java:83)
  io.helidon.websocket.ClientWsFrame.read(ClientWsFrame.java:125)
  io.helidon.webserver.websocket.WsConnection.readFrame(WsConnection.java:247)
  io.helidon.webserver.websocket.WsConnection.handle(WsConnection.java:107)
  io.helidon.webserver.http1.Http1Connection.handle(Http1Connection.java:160)
  io.helidon.webserver.ConnectionHandler.run(ConnectionHandler.java:155)
  ... (3 more)

Steps to reproduce

I have a simple websocket built like so:

WebServer.builder()
    .port(3000)
    .addRouting(WsRouting.builder().endpoint("/yapper", new WsListener() {
        @Override
         public void onMessage(final WsSession session, final String text, final boolean last) {
             System.out.printf("msg: %s, last: %b%n", text.trim(), last);
             session.send("yap!", true);
         }
    }))
    .build()
    .start();            

In a separate terminal I run:

./websocat ws://localhost:3000/yapper -t -

I can say "hi" and it replies with "yap!". My program prints "hi".
I can say "something else" and it replies with "yap!". My program prints "something else".
I then do Ctrl+C on websocat. websocat exits. My program throws the exception above.
Notice in the stack trace no line corresponds to my own code. It's all internal Helidon code.

@danielkec danielkec self-assigned this Oct 25, 2023
@danielkec danielkec added websocket WebSocket in Helidon 4.x Version 4.x labels Oct 25, 2023
danielkec added a commit to danielkec/helidon that referenced this issue Oct 25, 2023
@danielkec danielkec linked a pull request Oct 25, 2023 that will close this issue
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x websocket WebSocket in Helidon
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants