diff --git a/conn.go b/conn.go index 25b5a202482512dd1a1def94ddfe0ac6406bf3d0..ab37248eb3144998575d171ce76b31fc4d51c5d9 100644 --- a/conn.go +++ b/conn.go @@ -205,7 +205,7 @@ func (c *Conn) Ping(ctx context.Context) error { } func (c *Conn) ping(ctx context.Context, p string) error { - pong := make(chan struct{}) + pong := make(chan struct{}, 1) c.activePingsMu.Lock() c.activePings[p] = pong diff --git a/read.go b/read.go index 19727fda6bc975d5bfff2a962c69aaef79c21ab9..98766d7dbe0361f2a3146d4b06816605ace686df 100644 --- a/read.go +++ b/read.go @@ -283,7 +283,10 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) { pong, ok := c.activePings[string(b)] c.activePingsMu.Unlock() if ok { - close(pong) + select { + case pong <- struct{}{}: + default: + } } return nil }