From 7f9fea5797c6dd9cc682f4b0db1628c77a17457a Mon Sep 17 00:00:00 2001 From: WofWca Date: Sat, 7 Sep 2024 17:32:35 +0400 Subject: [PATCH] fix(proxy): send answer even if ICE gathering is not complete Otherwise the connection is guaranteed to fail, even though we actually might have gathered enough to make a successful connection. Closes https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40230 This is the standalone proxy counterpart of https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake-webext/-/merge_requests/55 --- proxy/lib/snowflake.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go index 176898a..9829d94 100644 --- a/proxy/lib/snowflake.go +++ b/proxy/lib/snowflake.go @@ -50,6 +50,8 @@ import ( "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/task" "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/util" "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/websocketconn" + + snowflakeClient "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/client/lib" ) const ( @@ -529,8 +531,15 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer( 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(snowflakeClient.DataChannelTimeout / 2): + log.Print("ICE gathering is not yet complete, but let's send the answer" + + " before the client times out") + } if !strings.Contains(pc.LocalDescription().SDP, "\na=candidate:") { return nil, fmt.Errorf("SDP answer contains no candidate")