From f2eec8c939b25815989d8190710ecb174b1e8001 Mon Sep 17 00:00:00 2001 From: Matt Jibson Date: Mon, 17 Nov 2014 19:11:36 -0500 Subject: [PATCH] Allow shutdown after timeout If a timeout has occurred, the send to recv in recvICMP would block forever because no goroutine was receiving on that channel anymore. This leaves behind 2 goroutines for each timeout: 1 trying to send an recv, and another waiting for the wait group. Instead, used a buffered channel so that the sender can send even with no listener. This cleans up the goroutines and collects the channel. --- fastping.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastping.go b/fastping.go index 813b6d4..2dc2727 100644 --- a/fastping.go +++ b/fastping.go @@ -315,7 +315,7 @@ func (p *Pinger) run(once bool) { defer conn6.Close() } - recv := make(chan *packet) + recv := make(chan *packet, 1) recvCtx := newContext() wg := new(sync.WaitGroup)