mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
fix(proxy): race condition warning for isClosing
It appears that there is no need for the `isClosing` var at all: we can just `close(c.sendMoreCh)` to ensure that it doesn't block any more `Write()`s. This is a follow-up to https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/144. Related: https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/524.
This commit is contained in:
parent
1aa5a61fe8
commit
01819eee32
2 changed files with 5 additions and 9 deletions
|
@ -485,6 +485,10 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(
|
|||
}
|
||||
})
|
||||
dc.OnClose(func() {
|
||||
// Make sure that the `Write()`s are not blocked any more.
|
||||
dc.OnBufferedAmountLow(func() {})
|
||||
close(conn.sendMoreCh)
|
||||
|
||||
conn.lock.Lock()
|
||||
defer conn.lock.Unlock()
|
||||
log.Printf("Data Channel %s-%d close\n", dc.Label(), dc.ID())
|
||||
|
|
|
@ -33,8 +33,6 @@ type webRTCConn struct {
|
|||
lock sync.Mutex // Synchronization for DataChannel destruction
|
||||
once sync.Once // Synchronization for PeerConnection destruction
|
||||
|
||||
isClosing bool
|
||||
|
||||
inactivityTimeout time.Duration
|
||||
activity chan struct{}
|
||||
sendMoreCh chan struct{}
|
||||
|
@ -45,7 +43,6 @@ type webRTCConn struct {
|
|||
|
||||
func newWebRTCConn(pc *webrtc.PeerConnection, dc *webrtc.DataChannel, pr *io.PipeReader, bytesLogger bytesLogger) *webRTCConn {
|
||||
conn := &webRTCConn{pc: pc, dc: dc, pr: pr, bytesLogger: bytesLogger}
|
||||
conn.isClosing = false
|
||||
conn.activity = make(chan struct{}, 100)
|
||||
conn.sendMoreCh = make(chan struct{}, 1)
|
||||
conn.inactivityTimeout = 30 * time.Second
|
||||
|
@ -89,7 +86,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() >= maxBufferedAmount {
|
||||
if c.dc.BufferedAmount() >= maxBufferedAmount {
|
||||
<-c.sendMoreCh
|
||||
}
|
||||
}
|
||||
|
@ -97,11 +94,6 @@ func (c *webRTCConn) Write(b []byte) (int, error) {
|
|||
}
|
||||
|
||||
func (c *webRTCConn) Close() (err error) {
|
||||
c.isClosing = true
|
||||
select {
|
||||
case c.sendMoreCh <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
c.once.Do(func() {
|
||||
c.cancelTimeoutLoop()
|
||||
err = errors.Join(c.pr.Close(), c.pc.Close())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue