Make server-side pre-connection errors observable via a log callback#595
Merged
Conversation
…ix #593) Server-side TLS handshake failures (and other pre-connection errors such as accept failures or hitting max connections) were only written to stderr by SocketServer::logError, so applications wired to setOnClientMessageCallback never saw them - unlike the client side, which reports TLS failures through the Error message callback. - Add SocketServer::setLogCallback(LogLevel, message): when set, server log messages are delivered to the callback instead of stderr/stdout. Applies to WebSocketServer and HttpServer alike. - Include the client ip and port in the tls accept failure and socket creation error messages. - Add a unittest exercising a failed TLS handshake against a wss server and asserting the error reaches the callback with the peer address. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
@bsergean Hey thanks for the swish update on this. Can you please tell when will be the next release? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #593
Problem
When a TLS handshake fails on the server before a WebSocket connection is established, the error is only written to stderr via the internal
logError(). Applications wired tosetOnClientMessageCallbacksee nothing — no error, no client IP — while the client side reports the same class of failure through itsErrormessage callback. The handshake runs inSocketServer::run()before anyWebSocketobject exists, so the existing callbacks can't be reached at that point.Changes
SocketServer::setLogCallback(LogLevel level, const std::string& message)— when set, server log messages (errors and info) are delivered to the callback instead of being written to stderr/stdout. This covers all pre-connection failures: TLS accept, socket accept errors, max-connections rejections, socket creation. Works forWebSocketServerandHttpServeralike. Default behavior is unchanged when no callback is set.tls accept failedandcannot create socketerror messages now include the clientip:port, which was already known at that point but not reported.wssserver, connects with a plaintext client so the TLS handshake fails, and asserts the error (including the peer address) reaches the log callback.docs/usage.md.Example log line now delivered to the application:
Test plan
IXWebSocketServerTestpasses locally (macOS, OpenSSL build), including the new TLS-failure test.🤖 Generated with Claude Code