From b7c2c56a23e7c468141ae14417167670e79ec525 Mon Sep 17 00:00:00 2001 From: Sergey Egorov Date: Sat, 29 Jan 2022 19:16:16 +0200 Subject: [PATCH] zmq4: fix REP socket races on client connection Fixes #119. Co-authored-by: Sergey Egorov --- rep.go | 2 +- socket.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rep.go b/rep.go index 5d31423..8ca6f2a 100644 --- a/rep.go +++ b/rep.go @@ -114,10 +114,10 @@ func newRepReader(ctx context.Context, state *repState) *repReader { } func (r *repReader) addConn(c *Conn) { - go r.listen(r.ctx, c) r.mu.Lock() r.conns = append(r.conns, c) r.mu.Unlock() + go r.listen(r.ctx, c) } func (r *repReader) rmConn(conn *Conn) { diff --git a/socket.go b/socket.go index 021e3dc..6ea5719 100644 --- a/socket.go +++ b/socket.go @@ -280,12 +280,12 @@ func (sck *socket) addConn(c *Conn) { c.Peer.Meta[sysSockID] = uuid } sck.ids[uuid] = c - if sck.r != nil { - sck.r.addConn(c) - } if sck.w != nil { sck.w.addConn(c) } + if sck.r != nil { + sck.r.addConn(c) + } sck.mu.Unlock() }