Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
if err != nil {
247247
return 0, err
248248
}
249-
defer func() {
250-
// We leave it locked when writing the close frame to avoid
251-
// any other goroutine writing any other frame.
252-
if opcode != opClose {
253-
c.writeFrameMu.unlock()
249+
defer c.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+
if wroteClose && opcode != opClose {
260+
select {
261+
case <-ctx.Done():
262+
return 0, ctx.Err()
263+
case <-c.closed:
264+
return 0, c.closeErr
254265
}
255-
}()
266+
}
256267

257268
select {
258269
case <-c.closed:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /