diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2022-09-17 11:28:31 +0100 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2022-09-17 11:28:31 +0100 |
| commit | 2bfa4630c7223ee11ec29b91107333758e7f2a8e (patch) | |
| tree | 8ca479f06a035c3f34a38bc77274ae8bf1a096d2 | |
| parent | f28ee4c120a248d06ad4b09d9fea8105cb192b48 (diff) | |
Close pipe if PipeListener.DialContext errors out
| -rw-r--r-- | net.go | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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) { |
