Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
1 change: 1 addition & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Conn struct {
writeBuf []byte
writeHeaderBuf [8]byte
writeHeader header
closeSent bool

closeReadMu sync.Mutex
closeReadCtx context.Context
Expand Down
13 changes: 13 additions & 0 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco
}
defer c.writeFrameMu.unlock()

if c.closeSent {
select {
case <-c.closed:
return 0, net.ErrClosed
default:
}
return 0, errors.New("close sent")
}

select {
case <-c.closed:
return 0, net.ErrClosed
Expand Down Expand Up @@ -303,6 +312,10 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco
}
}

if opcode == opClose {
c.closeSent = true
}

select {
case <-c.closed:
if opcode == opClose {
Expand Down
Loading