@@ -31,6 +31,7 @@ type pState struct {
3131 stdoutPipe io.ReadCloser
3232 stderrPipe io.ReadCloser
3333 exitStatus * int
34+ outClosed bool
3435 waitChan chan int
3536}
3637
@@ -86,15 +87,16 @@ func (h *jsonBasedHyperstart) Close() {
8687 defer h .Unlock ()
8788 if ! h .closed {
8889 h .Log (TRACE , "close jsonBasedHyperstart" )
90+ for _ , out := range h .streamOuts {
91+ out .Close ()
92+ }
93+ h .streamOuts = make (map [uint64 ]streamOut )
8994 for pk , ps := range h .procs {
95+ ps .outClosed = true
9096 ps .exitStatus = makeExitStatus (255 )
9197 h .handleWaitProcess (pk , ps )
9298 }
9399 h .procs = make (map [pKey ]* pState )
94- for _ , out := range h .streamOuts {
95- out .Close ()
96- }
97- h .streamOuts = make (map [uint64 ]streamOut )
98100 close (h .ctlChan )
99101 close (h .streamChan )
100102 for cmd := range h .ctlChan {
@@ -458,7 +460,7 @@ func handleStreamFromHyperstart(h *jsonBasedHyperstart, conn io.Reader) {
458460func makeExitStatus (status int ) * int { return & status }
459461
460462func (h * jsonBasedHyperstart ) handleWaitProcess (pk pKey , ps * pState ) {
461- if ps .exitStatus != nil && ps .waitChan != nil {
463+ if ps .exitStatus != nil && ps .waitChan != nil && ps . outClosed {
462464 delete (h .procs , pk )
463465 ps .waitChan <- * ps .exitStatus
464466 }
@@ -492,8 +494,17 @@ func (h *jsonBasedHyperstart) removeStreamOut(seq uint64) {
492494 // doesn't send eof of the stderr back, so we also remove stderr seq here
493495 if out , ok := h .streamOuts [seq ]; ok {
494496 delete (h .streamOuts , seq )
495- if seq == out .ps .stdioSeq && out .ps .stderrSeq > 0 {
496- delete (h .streamOuts , out .ps .stderrSeq )
497+ if seq == out .ps .stdioSeq {
498+ if out .ps .stderrSeq > 0 {
499+ h .streamOuts [out .ps .stderrSeq ].Close ()
500+ delete (h .streamOuts , out .ps .stderrSeq )
501+ }
502+ for pk , ps := range h .procs {
503+ if ps .stdioSeq == seq {
504+ ps .outClosed = true
505+ h .handleWaitProcess (pk , ps )
506+ }
507+ }
497508 }
498509 }
499510}
0 commit comments