mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
fix(probetest): maybe resource leak
...on failed requests: WebRTC connection wouldn't get closed in such cases.
This commit is contained in:
parent
51edbbfd26
commit
2d13e2a5d1
1 changed files with 11 additions and 0 deletions
|
@ -141,6 +141,16 @@ func probeHandler(stunURL string, w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// We'll set this to `false` if the signaling (this function) succeeds.
|
||||||
|
closePcOnReturn := true
|
||||||
|
defer func() {
|
||||||
|
if closePcOnReturn {
|
||||||
|
if err := pc.Close(); err != nil {
|
||||||
|
log.Printf("Error calling pc.Close: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Otherwise it must be closed below, wherever `closePcOnReturn` is set to `false`.
|
||||||
|
}()
|
||||||
|
|
||||||
sdp = &webrtc.SessionDescription{
|
sdp = &webrtc.SessionDescription{
|
||||||
Type: pc.LocalDescription().Type,
|
Type: pc.LocalDescription().Type,
|
||||||
|
@ -163,6 +173,7 @@ func probeHandler(stunURL string, w http.ResponseWriter, r *http.Request) {
|
||||||
// Set a timeout on peerconnection. If the connection state has not
|
// Set a timeout on peerconnection. If the connection state has not
|
||||||
// advanced to PeerConnectionStateConnected in this time,
|
// advanced to PeerConnectionStateConnected in this time,
|
||||||
// destroy the peer connection and return the token.
|
// destroy the peer connection and return the token.
|
||||||
|
closePcOnReturn = false
|
||||||
go func() {
|
go func() {
|
||||||
timer := time.NewTimer(dataChannelTimeout)
|
timer := time.NewTimer(dataChannelTimeout)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue