Skip to content

Commit 2157bff

Browse files
authored
fix: Clean up conn on NewStream error in memDRPC (#6182)
1 parent d355783 commit 2157bff

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

provisionersdk/transport.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,18 @@ func (m *memDRPC) NewStream(ctx context.Context, rpc string, enc drpc.Encoding)
110110
}
111111
dConn := drpcconn.New(conn)
112112
stream, err := dConn.NewStream(ctx, rpc, enc)
113-
if err == nil {
114-
go func() {
115-
select {
116-
case <-stream.Context().Done():
117-
case <-m.closed:
118-
}
119-
_ = dConn.Close()
120-
_ = conn.Close()
121-
}()
113+
if err != nil {
114+
_ = dConn.Close()
115+
_ = conn.Close()
116+
return nil, err
122117
}
123-
return stream, err
118+
go func() {
119+
select {
120+
case <-stream.Context().Done():
121+
case <-m.closed:
122+
}
123+
_ = dConn.Close()
124+
_ = conn.Close()
125+
}()
126+
return stream, nil
124127
}

0 commit comments

Comments
 (0)