fix: WebSocket proxy drops text frames — receive_bytes() silently fails on auth token
terminal.js sends the ttyd auth token as a TEXT WebSocket frame. The proxy's client_to_ttyd() called receive_bytes() which fails silently on text frames, swallows the exception, and exits — auth never reached ttyd, ttyd never started streaming, resulting in permanent black screen and reconnect loop. Fix: use receive() and dispatch on message type, handling both bytes and text.
This commit is contained in:
+5
-2
@@ -365,8 +365,11 @@ async def terminal_ws_proxy(websocket: WebSocket) -> None:
|
|||||||
async def client_to_ttyd() -> None:
|
async def client_to_ttyd() -> None:
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
data = await websocket.receive_bytes()
|
msg = await websocket.receive()
|
||||||
await ttyd_ws.send(data)
|
if msg.get("bytes"):
|
||||||
|
await ttyd_ws.send(msg["bytes"])
|
||||||
|
elif msg.get("text"):
|
||||||
|
await ttyd_ws.send(msg["text"])
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
"""
|
||||||
|
Regression tests for the WebSocket proxy in muxplex/main.py.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import inspect
|
||||||
|
|
||||||
|
from muxplex.main import terminal_ws_proxy
|
||||||
|
|
||||||
|
|
||||||
|
def test_terminal_ws_proxy_does_not_use_receive_bytes():
|
||||||
|
"""Regression: receive_bytes() silently drops TEXT frames (like the ttyd auth token).
|
||||||
|
|
||||||
|
terminal.js sends {"AuthToken": ""} as a TEXT WebSocket frame. The original
|
||||||
|
proxy used receive_bytes() which fails on text frames, swallowed the exception,
|
||||||
|
and exited — meaning ttyd never received the auth token, never started
|
||||||
|
streaming, resulting in a permanent black screen and reconnect loop.
|
||||||
|
|
||||||
|
The proxy MUST use receive() and dispatch on message type to handle both
|
||||||
|
binary and text frames correctly.
|
||||||
|
"""
|
||||||
|
source = inspect.getsource(terminal_ws_proxy)
|
||||||
|
assert "receive_bytes" not in source, (
|
||||||
|
"client_to_ttyd must not use receive_bytes() — silently drops text frames "
|
||||||
|
'like the ttyd auth token {"AuthToken": ""}'
|
||||||
|
)
|
||||||
|
assert ".receive()" in source, (
|
||||||
|
"client_to_ttyd must use receive() to handle both text and binary frames"
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user