mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
fix(probetest): NAT check timing out sometimes
if ICE gathering on the probetest server is taking long to complete. Related: https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40230
This commit is contained in:
parent
2d13e2a5d1
commit
55c4c90a3a
1 changed files with 13 additions and 4 deletions
|
@ -46,7 +46,7 @@ func (h ProbeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
// Create a PeerConnection from an SDP offer. Blocks until the gathering of ICE
|
||||
// candidates is complete and the answer is available in LocalDescription.
|
||||
func makePeerConnectionFromOffer(stunURL string, sdp *webrtc.SessionDescription,
|
||||
dataChan chan struct{}) (*webrtc.PeerConnection, error) {
|
||||
dataChan chan struct{}, iceGatheringTimeout time.Duration) (*webrtc.PeerConnection, error) {
|
||||
|
||||
settingsEngine := webrtc.SettingEngine{}
|
||||
// Use the SetNet setting https://pkg.go.dev/github.com/pion/webrtc/v3#SettingEngine.SetNet
|
||||
|
@ -102,8 +102,14 @@ func makePeerConnectionFromOffer(stunURL string, sdp *webrtc.SessionDescription,
|
|||
}
|
||||
return nil, err
|
||||
}
|
||||
// Wait for ICE candidate gathering to complete
|
||||
<-done
|
||||
|
||||
// Wait for ICE candidate gathering to complete,
|
||||
// or for whatever we managed to gather before the client times out.
|
||||
// See https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40230
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(iceGatheringTimeout):
|
||||
}
|
||||
return pc, nil
|
||||
}
|
||||
|
||||
|
@ -135,7 +141,10 @@ func probeHandler(stunURL string, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
dataChan := make(chan struct{})
|
||||
pc, err := makePeerConnectionFromOffer(stunURL, sdp, dataChan)
|
||||
// TODO refactor: DRY this must be below `ResponseHeaderTimeout` in proxy
|
||||
// https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/blob/e1d9b4ace69897521cc29585b5084c5f4d1ce874/proxy/lib/snowflake.go#L207
|
||||
iceGatheringTimeout := 10 * time.Second
|
||||
pc, err := makePeerConnectionFromOffer(stunURL, sdp, dataChan, iceGatheringTimeout)
|
||||
if err != nil {
|
||||
log.Printf("Error making WebRTC connection: %s", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue