Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Clean up conn on NewStream error in memDRPC
  • Loading branch information
mafredri committed Feb 13, 2023
commit e70d1df1861517e0858c7da4c3deb8f42eb3f21f
23 changes: 13 additions & 10 deletions provisionersdk/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,18 @@ func (m *memDRPC) NewStream(ctx context.Context, rpc string, enc drpc.Encoding)
}
dConn := drpcconn.New(conn)
stream, err := dConn.NewStream(ctx, rpc, enc)
if err == nil {
go func() {
select {
case <-stream.Context().Done():
case <-m.closed:
}
_ = dConn.Close()
_ = conn.Close()
}()
if err != nil {
_ = dConn.Close()
_ = conn.Close()
return nil, err
}
return stream, err
go func() {
select {
case <-stream.Context().Done():
case <-m.closed:
}
_ = dConn.Close()
_ = conn.Close()
}()
return stream, nil
}