mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-10-26 01:50:40 +08:00
writeWS held wsMu only to read p.ws, then released the mutex before calling ws.WriteJSON. Concurrent senders (sendMessage / SendImage / SendFile from the engine, plus the pingLoop heartbeat which DID hold the mutex through its own WriteJSON) could therefore enter WriteJSON in parallel. gorilla/websocket explicitly requires that no more than one goroutine call the write methods at a time and panics on detection: "panic: concurrent write to websocket connection". Hold wsMu through the entire WriteJSON, matching the pattern pingLoop already uses. Adds a regression test that fires 50 concurrent sends against an httptest websocket server; under -race the buggy version reliably panics in gorilla's beginMessage, while the fixed version serializes cleanly and the server receives all 50 frames as valid JSON.