mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
fix: Clean up conn on NewStream error in memDRPC (#6182)
This commit is contained in:
+13
-10
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user