WebSocketServer crashes when overridden methods throw Exceptions

Author: cvilsmeierCreated Jul 30, 2025Updated Nov 11, 2025

Describe the bug WebSocketServer crashes when overridden methods (onClose, onError) throw Exceptions. It hit us in production: Due to circumstances, our implementation threw some exceptions in the wrong places for one "bad" websocket client. The exceptions led to the WebSocketServer crash: The server wasn't accepting any more client connections, even from "good" clients.

To Reproduce Steps to reproduce the behavior: I've prepared a minimal reproducer:

  1. Go to https://gist.github.com/cvilsmeier/de7d1f3419f421de132b1acf16e7b04f
  2. Execute the program

Example application to reproduce the issue Please see https://gist.github.com/cvilsmeier/de7d1f3419f421de132b1acf16e7b04f

Expected behavior Maybe more "desirable" would be a WebSocketServer that stays up, no matter which exceptions are thrown in the "onOpen" and "onError" method implementations.

Environment(please complete the following information):

Thank you for your websocket library.

Source: TooTallNate/Java-WebSocket