mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -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
|
@ -452,12 +452,17 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
|
||||||
var n int
|
var n int
|
||||||
n, err = pw.Write(msg.Data)
|
n, err = pw.Write(msg.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if inerr := pw.CloseWithError(err); inerr != nil {
|
if inErr := pw.CloseWithError(err); inErr != nil {
|
||||||
log.Printf("close with error generated an error: %v", inerr)
|
log.Printf("close with error generated an error: %v", inErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.bytesLogger.AddOutbound(int64(n))
|
conn.bytesLogger.AddOutbound(int64(n))
|
||||||
|
|
||||||
if n != len(msg.Data) {
|
if n != len(msg.Data) {
|
||||||
|
// XXX: Maybe don't panic here and log an error instead?
|
||||||
panic("short write")
|
panic("short write")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,7 @@ package snowflake_proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
@ -62,7 +63,7 @@ func (c *webRTCConn) timeoutLoop(ctx context.Context) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
c.Close()
|
_ = c.Close()
|
||||||
log.Println("Closed connection due to inactivity")
|
log.Println("Closed connection due to inactivity")
|
||||||
return
|
return
|
||||||
case <-c.activity:
|
case <-c.activity:
|
||||||
|
@ -90,7 +91,7 @@ func (c *webRTCConn) Write(b []byte) (int, error) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
if c.dc != nil {
|
if c.dc != nil {
|
||||||
c.dc.Send(b)
|
_ = c.dc.Send(b)
|
||||||
if !c.isClosing && c.dc.BufferedAmount() >= maxBufferedAmount {
|
if !c.isClosing && c.dc.BufferedAmount() >= maxBufferedAmount {
|
||||||
<-c.sendMoreCh
|
<-c.sendMoreCh
|
||||||
}
|
}
|
||||||
|
@ -106,7 +107,7 @@ func (c *webRTCConn) Close() (err error) {
|
||||||
}
|
}
|
||||||
c.once.Do(func() {
|
c.once.Do(func() {
|
||||||
c.cancelTimeoutLoop()
|
c.cancelTimeoutLoop()
|
||||||
err = c.pc.Close()
|
err = errors.Join(c.pr.Close(), c.pc.Close())
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue