diff options
author | David Fifield <david@bamsoftware.com> | 2021-05-19 13:03:23 +0200 |
---|---|---|
committer | meskio <meskio@torproject.org> | 2021-05-21 10:09:00 +0200 |
commit | ef4d0a1da56e15327173923fa14a28d9ca40789c (patch) | |
tree | 9b1dd7c96db4772722ebdba5ee1acf65584a5f02 /probetest | |
parent | 7ef49272fa8c4169a5ec13988a71011dbe14bbfb (diff) | |
download | snowflake-ef4d0a1da56e15327173923fa14a28d9ca40789c.tar.gz snowflake-ef4d0a1da56e15327173923fa14a28d9ca40789c.zip |
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
Diffstat (limited to 'probetest')
-rw-r--r-- | probetest/probetest.go | 6 |
1 files changed, 5 insertions, 1 deletions
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) } |