Skip to content

Commit 9425bd0

Browse files
committed
fix(docker): prevent terminal hang after exec process exits
1 parent 3d5c222 commit 9425bd0

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

internal/docker/docker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,19 @@ func (c *Client) ExecInteractive(ctx context.Context, containerID string, args [
365365
}()
366366
}
367367

368-
var wg sync.WaitGroup
369368
if stdin != nil {
370-
wg.Add(1)
371369
go func() {
372-
defer wg.Done()
373370
_, _ = io.Copy(attachResp.Conn, stdin)
374371
_ = attachResp.CloseWrite()
375372
}()
376373
}
377374

378375
_, copyErr := io.Copy(stdout, attachResp.Reader)
379376

380-
wg.Wait()
377+
// Exec finished — close connection to unblock the stdin goroutine if
378+
// it's in Conn.Write(). If blocked in os.Stdin.Read() (uninterruptible),
379+
// the goroutine exits harmlessly at process exit.
380+
attachResp.Close()
381381

382382
inspect, err := engineCli.ContainerExecInspect(ctx, execID)
383383
if err != nil {

0 commit comments

Comments
 (0)