From a615e8b1ab88ac91a1a5588c1d6e41698e7af043 Mon Sep 17 00:00:00 2001 From: WofWca Date: Sat, 7 Oct 2023 20:28:54 +0400 Subject: [PATCH] fix(proxy): remove _potential_ deadlock The `dc.Send()` should increase the `bufferedAmount` value, so there is no need to add the message length a second time. Also replace GT with GE, for the case where `BufferedAmountLowThreshold === maxBufferedAmount` Currently the deadlock cannot happen because `maxBufferedAmount` and `BufferedAmountLowThreshold` are too far apart, in fact the former is 2x the latter. See - https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/144#note_2902956 - https://github.com/pion/webrtc/pull/2473 - https://github.com/pion/webrtc/pull/2474 --- proxy/lib/webrtcconn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/lib/webrtcconn.go b/proxy/lib/webrtcconn.go index ee656cb..f84734f 100644 --- a/proxy/lib/webrtcconn.go +++ b/proxy/lib/webrtcconn.go @@ -91,7 +91,7 @@ func (c *webRTCConn) Write(b []byte) (int, error) { defer c.lock.Unlock() if c.dc != nil { c.dc.Send(b) - if !c.isClosing && c.dc.BufferedAmount()+uint64(len(b)) > maxBufferedAmount { + if !c.isClosing && c.dc.BufferedAmount() >= maxBufferedAmount { <-c.sendMoreCh } }