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
This commit is contained in:
WofWca 2023-10-07 20:28:54 +04:00 committed by Shelikhoo
parent d434549df8
commit a615e8b1ab
No known key found for this signature in database
GPG key ID: C4D5E79D22B25316

View file

@ -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
}
}