fix-incomplete-websocket-frame-handling #51
Merged
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.
This pull request introduces significant improvements to the WebSocket handling traits, focusing on enhanced error handling, validation, and logging for both frame and message processing. The changes make the codebase more robust against malformed data, oversized payloads, and client communication errors, while also improving observability for debugging and production monitoring.
WebSocket Frame Handling Enhancements (
HandlesWebSocketFrames)Validation and Error Handling:
Logging and Debugging:
logFrameDebugandlogFrameErrorhelper methods for consistent logging of frame processing events and errors, including summaries after decoding and details for encoded frames. [1] [2] [3]API Improvements:
sendPongnow accepts an optional payload and provides error handling and logging for failed frame sends.isValidOpcodemethod to centralize opcode validation logic.WebSocket Message Handling Enhancements (
HandlesWebSocketMessages)Validation and Error Handling:
sendErrorMessage, including timestamp and detailed logging for failures to send messages.API and Utility Methods:
validateMessageStructure,createMessage, andsendMessagemethods for structured message creation, validation, and sending to clients, with logging for both success and failure cases.Logging and Observability:
These changes collectively make the WebSocket server more robust, easier to debug, and safer against malformed or malicious input.