Skip to content

Commit 283ee56

Browse files
committed
write.go: Fix deadlock in writeFrame
Closes #248 Luckily, due to the 5s timeout on the close handshake, this would have had very minimal effects on anyone in production.
1 parent 15a1523 commit 283ee56

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

write.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco
257257
if err != nil {
258258
return 0, err
259259
}
260-
defer c.writeFrameMu.unlock()
261260

262261
// If the state says a close has already been written, we wait until
263262
// the connection is closed and return that error.
@@ -268,13 +267,15 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco
268267
wroteClose := c.wroteClose
269268
c.closeMu.Unlock()
270269
if wroteClose && opcode != opClose {
270+
c.writeFrameMu.unlock()
271271
select {
272272
case <-ctx.Done():
273273
return 0, ctx.Err()
274274
case <-c.closed:
275275
return 0, c.closeErr
276276
}
277277
}
278+
defer c.writeFrameMu.unlock()
278279

279280
select {
280281
case <-c.closed:

0 commit comments

Comments
 (0)