From ef4d0a1da56e15327173923fa14a28d9ca40789c Mon Sep 17 00:00:00 2001 From: David Fifield Date: Wed, 19 May 2021 13:03:23 +0200 Subject: [PATCH] Stop timers before expiration If we don't stop them explicitly, the timers will not get garbage collected until they timeout: https://medium.com/@oboturov/golang-time-after-is-not-garbage-collected-4cbc94740082 Related to #40039 --- probetest/probetest.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/probetest/probetest.go b/probetest/probetest.go index f9bc96b..4158fa5 100644 --- a/probetest/probetest.go +++ b/probetest/probetest.go @@ -147,10 +147,14 @@ func probeHandler(w http.ResponseWriter, r *http.Request) { // advanced to PeerConnectionStateConnected in this time, // destroy the peer connection and return the token. go func() { + timer := time.NewTimer(dataChannelTimeout) + defer timer.Stop() + select { case <-dataChan: - case <-time.After(dataChannelTimeout): + case <-timer.C: } + if err := pc.Close(); err != nil { log.Printf("Error calling pc.Close: %v", err) }