fix(multiplayer): bound websocket writes

This commit is contained in:
Josh Creek
2026-09-01 21:24:38 +01:00
parent 30a22c366b
commit 614b87f7e1
3 changed files with 34 additions and 2 deletions
+19
View File
@@ -3,6 +3,7 @@ package api
import (
"bufio"
"bytes"
"net"
"net/http"
"net/http/httptest"
"testing"
@@ -25,6 +26,24 @@ func TestWebSocketReaderRejectsOversizedControlFrame(t *testing.T) {
}
}
func TestWebSocketWriterDoesNotBlockForeverOnSlowClient(t *testing.T) {
sender, receiver := net.Pipe()
defer sender.Close()
defer receiver.Close()
done := make(chan error, 1)
go func() {
done <- writeWebSocketFrameWithDeadline(sender, 0x1, bytes.Repeat([]byte{'x'}, maxWebSocketFrame), 20*time.Millisecond)
}()
select {
case err := <-done:
if err == nil {
t.Fatal("write to a non-reading client unexpectedly succeeded")
}
case <-time.After(time.Second):
t.Fatal("write to a non-reading client blocked past its deadline")
}
}
func TestWebSocketHandshakeRequiresRFC6455Version(t *testing.T) {
service := &Service{}
request := httptest.NewRequest(http.MethodGet, "/v1/events", nil)