Commit b628457
fix: read exec exit code only after draining the output stream (#3766)
A created-but-not-yet-started exec is reported by the daemon as
{Running:false, ExitCode:null}, which the Docker Go SDK flattens to
exit code 0. Inspecting immediately after attach could land in the
pre-start window and return 0 for a command still running.
Drain the hijacked stream to EOF before inspecting: the daemon closes
the stream only once the exec process has exited, making the subsequent
Running:false a real terminal state. The output is buffered internally
so callers still read it from the returned reader unchanged. On context
cancellation Exec returns ctx.Err() promptly; the deferred hijack.Close
unblocks the reader goroutine.
Also closes the hijacked response, which was previously leaked.
Co-authored-by: Dean Balandin <dbalandin@island.io>1 parent abc841d commit b628457
2 files changed
Lines changed: 54 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
586 | 587 | | |
587 | 588 | | |
588 | 589 | | |
| 590 | + | |
589 | 591 | | |
590 | | - | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
591 | 613 | | |
592 | 614 | | |
593 | 615 | | |
594 | 616 | | |
595 | 617 | | |
596 | 618 | | |
597 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
598 | 623 | | |
599 | 624 | | |
600 | 625 | | |
| |||
607 | 632 | | |
608 | 633 | | |
609 | 634 | | |
610 | | - | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
611 | 640 | | |
612 | 641 | | |
613 | 642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
74 | 97 | | |
75 | 98 | | |
76 | 99 | | |
| |||
0 commit comments