Skip to content

Commit

Permalink
bug: fix the data race in test on Windows (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed May 24, 2023
1 parent f6de680 commit bdcc30c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 3 additions & 9 deletions connection_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ func packTCPConn(c *conn, buf []byte) *tcpConn {

func unpackTCPConn(tc *tcpConn) {
tc.c.buffer = tc.buf
tc.buf = nil
}

func resetTCPConn(tc *tcpConn) {
bbPool.Put(tc.buf)
bbPool.Put(tc.c.buffer)
tc.c.buffer = nil
}

Expand All @@ -83,7 +84,7 @@ func newTCPConn(nc net.Conn, el *eventloop) (c *conn) {
return
}

func (c *conn) releaseTCP() {
func (c *conn) release() {
c.ctx = nil
c.localAddr = nil
c.remoteAddr = nil
Expand All @@ -102,13 +103,6 @@ func newUDPConn(el *eventloop, localAddr, remoteAddr net.Addr) *conn {
}
}

func (c *conn) releaseUDP() {
c.ctx = nil
c.localAddr = nil
bbPool.Put(c.buffer)
c.buffer = nil
}

func (c *conn) resetBuffer() {
c.buffer.Reset()
c.inboundBuffer.Reset()
Expand Down
6 changes: 3 additions & 3 deletions eventloop_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (el *eventloop) readUDP(c *conn) error {
if action == Shutdown {
return errors.ErrEngineShutdown
}
c.releaseUDP()
c.release()
return nil
}

Expand Down Expand Up @@ -187,7 +187,7 @@ func (el *eventloop) close(c *conn, err error) error {
el.getLogger().Errorf("failed to close connection(%s), error:%v", c.remoteAddr.String(), err)
}
}
c.releaseUDP()
c.release()
return el.handleAction(c, action)
}

Expand All @@ -201,7 +201,7 @@ func (el *eventloop) close(c *conn, err error) error {
}
delete(el.connections, c)
el.incConn(-1)
c.releaseTCP()
c.release()

return el.handleAction(c, action)
}
Expand Down

0 comments on commit bdcc30c

Please sign in to comment.