fix(chain): Copy returns wrong pointer, connection leaks in Connect/Handshake, deferred cancel accumulation in retry loops
- transport.go: Copy() returned original pointer instead of the allocated copy, causing data races and incorrect routing for multiplexed chains. - route.go: Connect and Handshake failures in intermediate nodes leaked the returned connection. Handshake fix preserves the original Connect result (guaranteed non-nil) and closes both the Handshake return value and input. - router.go: defer cancel() inside retry loops accumulated context timers across iterations. Wrapped each loop body in an IIFE so defer scopes per-iteration and timers are released immediately.
This commit is contained in:
+10
-1
@@ -271,20 +271,29 @@ func (r *chainRoute) connect(ctx context.Context, logger logger.Logger) (conn ne
|
||||
}
|
||||
cc, err = preNode.Options().Transport.Connect(ctx, cn, "tcp", addr)
|
||||
if err != nil {
|
||||
if cc != nil {
|
||||
cc.Close()
|
||||
}
|
||||
cn.Close()
|
||||
if marker != nil {
|
||||
marker.Mark()
|
||||
}
|
||||
return
|
||||
}
|
||||
cc, err = node.Options().Transport.Handshake(ctx, cc)
|
||||
var cc2 net.Conn
|
||||
cc2, err = node.Options().Transport.Handshake(ctx, cc)
|
||||
if err != nil {
|
||||
if cc2 != nil {
|
||||
cc2.Close()
|
||||
}
|
||||
cc.Close()
|
||||
cn.Close()
|
||||
if marker != nil {
|
||||
marker.Mark()
|
||||
}
|
||||
return
|
||||
}
|
||||
cc = cc2
|
||||
if marker != nil {
|
||||
marker.Reset()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user