fix: 修复 server.Conn 连接关闭时发生的竞态问题

This commit is contained in:
kercylan98 2023-09-09 13:10:19 +08:00
parent 8fd4e8f722
commit 674c38a066
1 changed files with 2 additions and 0 deletions

View File

@ -169,6 +169,8 @@ func (slf *Conn) IsClosed() bool {
// Close 关闭连接
func (slf *Conn) Close(err ...error) {
slf.close.Do(func() {
slf.mutex.Lock()
defer slf.mutex.Unlock()
slf.closed = true
if slf.ws != nil {
_ = slf.ws.Close()