Skip to content

Commit

Permalink
adds a lock on writeClose. closes coder#448
Browse files Browse the repository at this point in the history
  • Loading branch information
FrauElster committed Sep 5, 2024
1 parent 3dd723a commit 0daf07f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions close.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ func (c *Conn) closeHandshake(code StatusCode, reason string) error {
}

func (c *Conn) writeClose(code StatusCode, reason string) error {
c.closeMu.Lock()
defer c.closeMu.Unlock()
if c.closeWritten {
return nil
}

ce := CloseError{
Code: code,
Reason: reason,
Expand All @@ -193,6 +199,7 @@ func (c *Conn) writeClose(code StatusCode, reason string) error {
if err != nil && !errors.Is(err, net.ErrClosed) {
return err
}
c.closeWritten = true
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ type Conn struct {
closeReadCtx context.Context
closeReadDone chan struct{}

closed chan struct{}
closeMu sync.Mutex
closing bool
closed chan struct{}
closeMu sync.Mutex
closing bool
closeWritten bool

pingCounter atomic.Int64
activePingsMu sync.Mutex
Expand Down

0 comments on commit 0daf07f

Please sign in to comment.