Skip to content

feat(ws): add read pump for disconnect detection, GetContext, Level.String#24

Merged
taigrr merged 1 commit into
masterfrom
cd/websocket-read-pump-and-level-stringer
Apr 15, 2026
Merged

feat(ws): add read pump for disconnect detection, GetContext, Level.String#24
taigrr merged 1 commit into
masterfrom
cd/websocket-read-pump-and-level-stringer

Conversation

@taigrr
Copy link
Copy Markdown
Owner

@taigrr taigrr commented Apr 7, 2026

Changes

WebSocket read pump

The LogSocketHandler previously never read from the WebSocket connection. This meant client disconnects were only detected when WriteMessage failed — which could be delayed indefinitely if no logs were being produced. A goroutine now continuously reads from the connection, and cancels a context when the client disconnects.

Client.GetContext(ctx)

New method that blocks until either a log entry arrives or the context is cancelled. Used by the WebSocket handler to cleanly exit when the read pump detects a disconnect. Also useful for any caller that needs cancellation support.

Level.String()

Implements fmt.Stringer on Level, returning the human-readable level name ("INFO", "WARN", etc.).

Tests

  • TestGetContext — verifies cancelled context returns false
  • TestGetContextReceivesEntry — verifies normal entry delivery
  • TestLevelString — verifies all level names including unknown

…tring

- Add WebSocket read pump in LogSocketHandler so client disconnects are
  detected promptly instead of only on the next WriteMessage call
- Add Client.GetContext(ctx) for context-aware blocking reads
- Implement fmt.Stringer on Level type (Level.String())
- Add tests for GetContext, GetContext cancellation, and Level.String()
@taigrr taigrr merged commit af56461 into master Apr 15, 2026
2 checks passed
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