summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-12-20 12:35:02 +0700
committerShulhan <ms@kilabit.info>2021-12-20 12:35:02 +0700
commitca9eea7cb8e07495719338c28fc15d2f951ca269 (patch)
tree9af82629bbcadf3f2dd9c9dc6d5c9406a48e81d6
parent213f0324a778711bcd053fb8b30591234c7527d9 (diff)
downloadpakakeh.go-ca9eea7cb8e07495719338c28fc15d2f951ca269.tar.xz
lib/websocket: fix race conditition on handleText
Instead of accessing the ctx field directly, call the Context() method to prevent data race.
-rw-r--r--lib/websocket/server.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/websocket/server.go b/lib/websocket/server.go
index a575f207..ff7cd2d3 100644
--- a/lib/websocket/server.go
+++ b/lib/websocket/server.go
@@ -221,7 +221,7 @@ func (serv *Server) clientAdd(ctx context.Context, conn int) (err error) {
// ClientRemove remove client connection from server.
//
func (serv *Server) ClientRemove(conn int) {
- ctx := serv.Clients.Context(conn)
+ ctx, _ := serv.Clients.Context(conn)
if ctx != nil && serv.Options.HandleClientRemove != nil {
serv.Options.HandleClientRemove(ctx, conn)
@@ -439,7 +439,7 @@ func (serv *Server) handleText(conn int, payload []byte) {
res := _resPool.Get().(*Response)
res.reset()
- ctx, ok := serv.Clients.ctx[conn]
+ ctx, ok := serv.Clients.Context(conn)
if !ok {
err = errors.New("client context not found")
res.Code = http.StatusInternalServerError