refactor: overhaul performance, RFC compliance, and robustness - #160
Open
shengyanli1982 wants to merge 2 commits into
Open
refactor: overhaul performance, RFC compliance, and robustness#160shengyanli1982 wants to merge 2 commits into
shengyanli1982 wants to merge 2 commits into
Conversation
broadcast with callback
Performance: - Introduce per-connection lock-free mask key generation via splitmix64 with atomic state, eliminating shared random source contention - Add fast-path doWriteBytes/genFrameBytes/compressDataBytes bypassing the Payload interface for []byte payloads - Pool Message structs via sync.Pool to reduce allocation pressure - Replace map-based BufferPool shard lookup with index-based O(1) access - Use strings.EqualFold for case-insensitive header comparison RFC Compliance: - RFC6455 §5.2: reject 64-bit payload lengths exceeding math.MaxInt - RFC7692: fix permessage-deflate window_bits negotiation so server never exceeds client offer; treat absent client_max_window_bits as 15 - Validate RSV bits on control frames and continuation frames per §5.2/§5.4 - Reject reserved close codes (1005/1006/1015) in WriteClose - Enforce control frame payload limit (125 bytes) in genFrame - Cross-slice UTF-8 validation for Buffers.CheckEncoding (Writev) Robustness: - Recover panics in OnOpen callback to prevent ReadLoop crash - Recover panics in workerQueue jobs to keep worker goroutines alive - Use buffered channel(1) in client handshake to prevent goroutine leak - Set read deadline during server handshake; close conn on failure - Clone TlsConfig before mutation to prevent shared state corruption - Reuse hijacked bufio.Reader when it contains pipelined data - Update compression dictionary only on successful write - Pass through semantic close status codes (e.g. 1009) without wrapping Code Quality: - Extract frameCursor struct to eliminate reader code duplication - Remove unused MaskByByte/NewMaskKey/MethodExists and reflect import - Add compress level validation with descriptive panic - Comply flateWriter.Write with io.Writer contract (return len(p)) - Strip all English doc comments, retain Chinese-only documentation - Bump minimum Go version to 1.23 Testing: - Add comprehensive tests for compression negotiation, frame validation, mask key generation, UTF-8 cross-slice checks, and edge cases
Owner
|
改动太多, 简化下, 非导出函数不要写太详细的注释, 其他地方加的注释绝大部分也要去掉. |
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.
No description provided.