Skip to content

refactor: overhaul performance, RFC compliance, and robustness - #160

Open
shengyanli1982 wants to merge 2 commits into
lxzan:devfrom
shengyanli1982:dev
Open

refactor: overhaul performance, RFC compliance, and robustness#160
shengyanli1982 wants to merge 2 commits into
lxzan:devfrom
shengyanli1982:dev

Conversation

@shengyanli1982

Copy link
Copy Markdown
Contributor

No description provided.

lxzan and others added 2 commits July 27, 2026 17:09
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
@lxzan

lxzan commented Sep 10, 2026

Copy link
Copy Markdown
Owner

改动太多, 简化下, 非导出函数不要写太详细的注释, 其他地方加的注释绝大部分也要去掉.

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.

2 participants