commit 08f5205461573bf8a6e8961540ac620865a3b45c Author: Cecylia Bocovich cohosh@torproject.org Date: Wed Apr 3 15:59:47 2019 -0400
Added check to see if peer connection succeeded
This is related to the proxy-go deadlock bug #25688. If a client doesn't do anything with the SDP answer, a token will get lost. Added a timeout after a minute that checks the PeerConnection state and destroys the peer connection and returns a token if did not yet succeed --- proxy-go/snowflake.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/proxy-go/snowflake.go b/proxy-go/snowflake.go index aeb9f51..1c24e47 100644 --- a/proxy-go/snowflake.go +++ b/proxy-go/snowflake.go @@ -307,9 +307,9 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
log.Println("Generating answer...") answer, err := pc.CreateAnswer() - // blocks on ICE gathering. we need to add a timeout if needed - // not putting this in a separate go routine, because we need - // SetLocalDescription(answer) to be called before sendAnswer + // blocks on ICE gathering. we need to add a timeout if needed + // not putting this in a separate go routine, because we need + // SetLocalDescription(answer) to be called before sendAnswer if err != nil { pc.Destroy() return nil, err @@ -325,6 +325,20 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc. pc.Destroy() return nil, err } + + // Set a timeout on peerconnection. If the connection state has not + // advanced to PeerConnectionStateConnected in this time, + // destroy the peer connection and return the token. + go func() { + <-time.After(time.Minute) + if pc.ConnectionState() != webrtc.PeerConnectionStateConnected { + log.Println("Timed out waiting for client to open data cannel.") + pc.Destroy() + retToken() + } + + }() + return pc, nil }