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

Avoid handling ping after close frame has been sent#394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
bhallionOhbibi wants to merge2 commits intocoder:devfrombhallionOhbibi:master
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletionsconn_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -553,3 +553,26 @@ func assertClose(tb testing.TB, c *websocket.Conn) {
err := c.Close(websocket.StatusNormalClosure, "")
assert.Success(tb, err)
}

func TestConcurrentClosePing(t *testing.T) {
t.Parallel()
for i := 0; i < 64; i++ {
func() {
c1, c2 := wstest.Pipe(nil, nil)
defer c1.CloseNow()
defer c2.CloseNow()
c1.CloseRead(context.Background())
c2.CloseRead(context.Background())
go func() {
for range time.Tick(time.Millisecond) {
if err := c1.Ping(context.Background()); err != nil {
return
}
}
}()

time.Sleep(10 * time.Millisecond)
assert.Success(t, c1.Close(websocket.StatusNormalClosure, ""))
}()
}
}
8 changes: 7 additions & 1 deletionread.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
//go:build !js
// +build !js

package websocket
Expand DownExpand Up@@ -287,6 +286,13 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) {

switch h.opcode {
case opPing:
c.closeMu.Lock()
wroteClose := c.wroteClose
c.closeMu.Unlock()
if wroteClose {
// Cannot respond to ping with a pong because we already sent a close frame.
return nil
}
return c.writeControl(ctx, opPong, b)
case opPong:
c.activePingsMu.Lock()
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp