aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2022-09-17 11:28:31 +0100
committerGrégoire Duchêne <gduchene@awhk.org>2022-09-17 11:28:31 +0100
commit2bfa4630c7223ee11ec29b91107333758e7f2a8e (patch)
tree8ca479f06a035c3f34a38bc77274ae8bf1a096d2
parentf28ee4c120a248d06ad4b09d9fea8105cb192b48 (diff)
Close pipe if PipeListener.DialContext errors out
-rw-r--r--net.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/net.go b/net.go
index 040fe66..aa1ccc3 100644
--- a/net.go
+++ b/net.go
@@ -63,16 +63,19 @@ func (p *PipeListener) Dial(_, _ string) (net.Conn, error) {
return p.DialContext(context.Background(), "", "")
}
-func (p *PipeListener) DialContext(ctx context.Context, _, _ string) (net.Conn, error) {
+func (p *PipeListener) DialContext(ctx context.Context, _, _ string) (_ net.Conn, err error) {
s, c := net.Pipe()
select {
case p.conns <- s:
return c, nil
case <-p.done:
- return nil, syscall.ECONNREFUSED
+ err = syscall.ECONNREFUSED
case <-ctx.Done():
- return nil, ctx.Err()
+ err = ctx.Err()
}
+ s.Close()
+ c.Close()
+ return
}
func (p *PipeListener) DialContextGRPC(ctx context.Context, _ string) (net.Conn, error) {