Commit 1276ec2b authored by ale's avatar ale

Fix a goroutine/channel leak on request timeout

parent e02d1ddf
Pipeline #1623 passed with stages
in 1 minute and 30 seconds
......@@ -28,14 +28,21 @@ func New(socketPath string) Client {
func (c *socketClient) Authenticate(ctx context.Context, req *auth.Request) (*auth.Response, error) {
// Create the connection outside of the timed goroutine, so
// that we can call Close() on exit regardless of the reason:
// this way, when a timeout occurs or the context is canceled,
// the pending request terminates immediately.
conn, err := textproto.Dial("unix", c.socketPath)
if err != nil {
return nil, err
defer conn.Close()
// Make space in the channel for at least one element, or we
// will leak a goroutine whenever the authentication request
// times out.
done := make(chan error, 1)
var resp auth.Response
done := make(chan error)
go func() {
defer close(done)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment