Skip to content

Commit 897a573

Browse files
authored
write.go: Fix deadlock in writeFrame (#253)
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 493ebbe commit 897a573

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

write.go

Lines changed: 2 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy