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
This commit is contained in:
David Fifield 2021-05-19 13:03:23 +02:00 committed by meskio
parent 7ef49272fa
commit ef4d0a1da5
No known key found for this signature in database
GPG key ID: 52B8F5AC97A2DA86

View file

@ -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)
}