Skip to content

Commit

Permalink
Prevent all writes after close
Browse files Browse the repository at this point in the history
Closes #213
  • Loading branch information
nhooyr committed Apr 14, 2020
1 parent c4d4650 commit d34c89a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion write.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco
if err != nil {
return 0, err
}
defer c.writeFrameMu.unlock()
defer func() {
// We leave it locked when writing the close frame to avoid
// any other goroutine writing any other frame.
if opcode != opClose {
c.writeFrameMu.unlock()
}
}()

select {
case <-c.closed:
Expand Down

0 comments on commit d34c89a

Please sign in to comment.