mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
fix(proxy): Correctly close connection pipe when dealing with error
This commit is contained in:
parent
6393af6bab
commit
7142fa3ddb
2 changed files with 11 additions and 5 deletions
|
@ -2,6 +2,7 @@ package snowflake_proxy
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -62,7 +63,7 @@ func (c *webRTCConn) timeoutLoop(ctx context.Context) {
|
|||
for {
|
||||
select {
|
||||
case <-timer.C:
|
||||
c.Close()
|
||||
_ = c.Close()
|
||||
log.Println("Closed connection due to inactivity")
|
||||
return
|
||||
case <-c.activity:
|
||||
|
@ -90,7 +91,7 @@ func (c *webRTCConn) Write(b []byte) (int, error) {
|
|||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
if c.dc != nil {
|
||||
c.dc.Send(b)
|
||||
_ = c.dc.Send(b)
|
||||
if !c.isClosing && c.dc.BufferedAmount() >= maxBufferedAmount {
|
||||
<-c.sendMoreCh
|
||||
}
|
||||
|
@ -106,7 +107,7 @@ func (c *webRTCConn) Close() (err error) {
|
|||
}
|
||||
c.once.Do(func() {
|
||||
c.cancelTimeoutLoop()
|
||||
err = c.pc.Close()
|
||||
err = errors.Join(c.pr.Close(), c.pc.Close())
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue