Skip to content

Conversation

@marktech0813
Copy link

I found where the server invokes your overridden callbacks and added guards so exceptions from onOpen, onClose, and onError cannot crash the selector thread. I also wrapped onStart similarly. Lints are clean.

What I changed

  • Guarded callback invocations in src/main/java/org/java_websocket/server/WebSocketServer.java:
  • Wrap onOpen, onClose, onError, and onStart in try/catch.
  • Log the exception and attempt to call onError(...); if onError itself throws, swallow and log to prevent propagation.
  • Outcome: Exceptions thrown by your overrides no longer bubble up to the server’s run loop; the server continues accepting connections even if a “bad” client triggers user code exceptions.

I found where the server invokes your overridden callbacks and added guards so exceptions from onOpen, onClose, and onError cannot crash the selector thread. I also wrapped onStart similarly. Lints are clean.
What I changed
- Guarded callback invocations in src/main/java/org/java_websocket/server/WebSocketServer.java:
  Wrap onOpen, onClose, onError, and onStart in try/catch.
  Log the exception and attempt to call onError(...); if onError itself throws, swallow and log to prevent propagation.
- Outcome: Exceptions thrown by your overrides no longer bubble up to the server’s run loop; the server continues accepting connections even if a “bad” client triggers user code exceptions.
@marktech0813 marktech0813 changed the title Handle exceptions in WebSocket event methods Fix : WebSocketServer crashes when overridden methods throw Exceptions #1481 Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant