Skip to content

Commit 02861b4

Browse files
authored
Merge pull request #238 from nhooyr/dev
Fix deadlock introduced in v1.8.5
2 parents 34417b2 + 03cca81 commit 02861b4

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

‎ci/all.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ main(){
66

77
./ci/fmt.sh
88
./ci/lint.sh
9-
./ci/test.sh
9+
./ci/test.sh"$@"
1010
}
1111

1212
main "$@"

‎write.go‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,24 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco
246246
iferr!=nil{
247247
return0, err
248248
}
249-
deferfunc(){
250-
// We leave it locked when writing the close frame to avoid
251-
// any other goroutine writing any other frame.
252-
ifopcode!=opClose{
253-
c.writeFrameMu.unlock()
249+
deferc.writeFrameMu.unlock()
250+
251+
// If the state says a close has already been written, we wait until
252+
// the connection is closed and return that error.
253+
//
254+
// However, if the frame being written is a close, that means its the close from
255+
// the state being set so we let it go through.
256+
c.closeMu.Lock()
257+
wroteClose:=c.wroteClose
258+
c.closeMu.Unlock()
259+
ifwroteClose&&opcode!=opClose{
260+
select{
261+
case<-ctx.Done():
262+
return0, ctx.Err()
263+
case<-c.closed:
264+
return0, c.closeErr
254265
}
255-
}()
266+
}
256267

257268
select{
258269
case<-c.closed:

0 commit comments

Comments
(0)