Movatterモバイル変換


[0]ホーム

URL:


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

Commit5a03e10

Browse files
committed
read: Fix CloseRead to have its own done channel
Context can be cancelled by parent. Doesn't indicate the CloseRead goroutinehas exited.
1 parentc63f0c1 commit5a03e10

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

‎close.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ func (c *Conn) waitGoroutines() error {
239239
}
240240

241241
c.closeReadMu.Lock()
242-
ctx:=c.closeReadCtx
242+
closeRead:=c.closeReadCtx!=nil
243243
c.closeReadMu.Unlock()
244-
ifctx!=nil {
244+
ifcloseRead {
245245
select {
246-
case<-ctx.Done():
246+
case<-c.closeReadDone:
247247
case<-t.C:
248248
returnerrors.New("failed to wait for close read goroutine to exit")
249249
}

‎conn.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ type Conn struct {
5757
timeoutLoopDonechanstruct{}
5858

5959
// Read state.
60-
readMu*mu
61-
readHeaderBuf[8]byte
62-
readControlBuf[maxControlPayload]byte
63-
msgReader*msgReader
60+
readMu*mu
61+
readHeaderBuf [8]byte
62+
readControlBuf [maxControlPayload]byte
63+
msgReader*msgReader
6464

6565
// Write state.
6666
msgWriter*msgWriter
@@ -69,8 +69,9 @@ type Conn struct {
6969
writeHeaderBuf [8]byte
7070
writeHeaderheader
7171

72-
closeReadMu sync.Mutex
73-
closeReadCtx context.Context
72+
closeReadMu sync.Mutex
73+
closeReadCtx context.Context
74+
closeReadDonechanstruct{}
7475

7576
closedchanstruct{}
7677
closeMu sync.Mutex

‎mask_asm.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package websocket
44

55
funcmask(b []byte,keyuint32)uint32 {
6-
// TODO: Will enable in v1.9.0.
6+
// TODO: Will enable in v1.9.0.
77
returnmaskGo(b,key)
88
iflen(b)>0 {
99
returnmaskAsm(&b[0],len(b),key)

‎read.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ func (c *Conn) CloseRead(ctx context.Context) context.Context {
7171
}
7272
ctx,cancel:=context.WithCancel(ctx)
7373
c.closeReadCtx=ctx
74+
c.closeReadDone=make(chanstruct{})
7475
c.closeReadMu.Unlock()
7576

7677
gofunc() {
78+
deferclose(c.closeReadDone)
7779
defercancel()
7880
deferc.close()
7981
_,_,err:=c.Reader(ctx)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp