From d1a4ca2ee5039cdc3c58ad76e50df619a6cdcb26 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 29 Jul 2022 00:40:25 +0700 Subject: lib/websocket: fix possible data race on client test We only do lock on exported methods, but when doing testing we call the send method without lock which cause read and write on Client.conn at the same time. --- lib/websocket/client_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/websocket/client_test.go b/lib/websocket/client_test.go index c609024b..8927b4bd 100644 --- a/lib/websocket/client_test.go +++ b/lib/websocket/client_test.go @@ -501,7 +501,9 @@ func TestClientFragmentation(t *testing.T) { for x = 0; x < len(c.frames); x++ { req = c.frames[x].pack() + testClient.Lock() err = testClient.send(req) + testClient.Unlock() if err != nil { // If the client send unmasked frame, the // server may close the connection before we -- cgit v1.3