Skip to content

Commit 37bfbae

Browse files
committed
Fix DOS attack from malicious pongs
Cherry picked from master at 129d303
1 parent 34e5591 commit 37bfbae

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (c *Conn) Ping(ctx context.Context) error {
205205
}
206206

207207
func (c *Conn) ping(ctx context.Context, p string) error {
208-
pong := make(chan struct{})
208+
pong := make(chan struct{}, 1)
209209

210210
c.activePingsMu.Lock()
211211
c.activePings[p] = pong

read.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) {
283283
pong, ok := c.activePings[string(b)]
284284
c.activePingsMu.Unlock()
285285
if ok {
286-
close(pong)
286+
select {
287+
case pong <- struct{}{}:
288+
default:
289+
}
287290
}
288291
return nil
289292
}

0 commit comments

Comments
 (0)