feat(access): migrate web console to coder/websocket with buffered relay and liveness keepalive#79
Open
jisung-02 wants to merge 7 commits into
Open
feat(access): migrate web console to coder/websocket with buffered relay and liveness keepalive#79jisung-02 wants to merge 7 commits into
jisung-02 wants to merge 7 commits into
Conversation
Replace golang.org/x/net/websocket with github.com/coder/websocket for the web console SSH relay. Validate origin before Accept, set a read limit, drive the connection with a Background-derived context, add a per-write deadline so a slow client cannot stall the SSH pump, and drop the per-write payload copy.
…WebSocket decorator Extract relayConsole as a transport-agnostic SSH core (ns-proxy dial with timeout, inner handshake, host key callback, pty/shell, io.Copy pumps) that takes an io.ReadWriteCloser, mirroring the ssh-gateway terminal path. The web console now wraps the WebSocket in a webSocketConsole adapter and injects it. Add a dial timeout/context to dialViaNSProxy.
Cap the batched output buffer per session and block the producer (via sync.Cond) when it is full, throttling the SSH read loop instead of buffering unbounded. This propagates flow control to the remote shell without dropping output; a slow or dead client still hits the write deadline and tears the session down.
Pull the per-flush output buffer from a sync.Pool and return it after the write completes, instead of allocating a fresh one each ~8ms window. Cuts allocations under heavy output; oversized buffers grown past the cap are dropped.
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.
개요
웹 콘솔(브라우저 ↔ VM SSH 릴레이)의 WebSocket 스택을 전면 개선합니다.
golang.org/x/net/websocket을github.com/coder/websocket으로 교체변경 사항
1. WebSocket 라이브러리 교체 (
coder/websocketv1.8.14)SetReadLimit)2. 릴레이 구조 분리
bridgeWebConsole(WebSocket 전용) →relayConsole(client io.ReadWriteCloser, ...)로 리팩토링.WebSocket은
webSocketConsole어댑터로 감싸서 전달 — 릴레이 코어는 전송 방식을 모름io.Copy펌프 + context 취소로 단순화dialViaNSProxy가 context를 받도록 변경)3. 출력 배칭 + 백프레셔 + 버퍼 풀링
Write가 블로킹되어 SSH 읽기 루프를 직접 늦춤(느린 클라이언트로 인한 무한 버퍼링 방지). WebSocket 쓰기 10초 타임아웃 초과 시 강제 종료
sync.Pool로 플러시 버퍼 재사용 → 대량 출력 시 GC 부담 감소4. keepalive + 세션 수명 제한 (
console_liveness.go)기존에는 유휴 상태에서 죽은 브라우저/VM을 감지할 방법이 없어 SSH 세션·고루틴·
authorized key 정리가 무기한 지연될 수 있었습니다. 30초 간격 단일 감시 루프가
아래를 한 번에 검사하고, 실패 시 원인(
context.WithCancelCause)을 담아 릴레이를종료합니다:
keepalive@openssh.com글로벌 요청 (OpenSSHServerAliveInterval과 동일)테스트
go test ./internal/domain/access/ -race통과SSH 프로브(성공/실패/행), 실제 WebSocket 왕복 ping 테스트 추가
참고
프론트엔드 작업과 함께 후속 PR에서 진행 예정