Commit 65672e54 authored by David Fifield's avatar David Fifield
Browse files

In lib.Handler, close resources even in case of an error.

Closes #40042.
parent eff73c30
Pipeline #5224 passed with stage
in 6 minutes and 45 seconds
......@@ -102,6 +102,10 @@ func Handler(socks net.Conn, tongue Tongue) error {
if err != nil {
return err
}
defer func() {
snowflakes.End()
log.Printf("---- Handler: end collecting snowflakes ---")
}()
// Use a real logger to periodically output how much traffic is happening.
snowflakes.BytesLogger = NewBytesSyncLogger()
......@@ -115,23 +119,25 @@ func Handler(socks net.Conn, tongue Tongue) error {
if err != nil {
return err
}
defer func() {
pconn.Close()
sess.Close()
log.Printf("---- Handler: discarding finished session ---")
}()
// On the smux session we overlay a stream.
stream, err := sess.OpenStream()
if err != nil {
return err
}
defer stream.Close()
defer func() {
stream.Close()
log.Printf("---- Handler: closed stream %v ---", stream.ID())
}()
log.Printf("---- Handler: begin stream %v ---", stream.ID())
// Begin exchanging data.
log.Printf("---- Handler: begin stream %v ---", stream.ID())
copyLoop(socks, stream)
log.Printf("---- Handler: closed stream %v ---", stream.ID())
snowflakes.End()
log.Printf("---- Handler: end collecting snowflakes ---")
pconn.Close()
sess.Close()
log.Printf("---- Handler: discarding finished session ---")
return nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment