From 2e01d90774fd0608f7c9b24a9987a0c7a2fb121d Mon Sep 17 00:00:00 2001 From: Seongbin Hong Date: Thu, 31 Aug 2023 14:33:44 +0900 Subject: [PATCH] fix tcp half-closed connection unreliability in WSL Signed-off-by: Seongbin Hong --- cli/command/container/hijack.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cli/command/container/hijack.go b/cli/command/container/hijack.go index cd91e69514..d6470a70a3 100644 --- a/cli/command/container/hijack.go +++ b/cli/command/container/hijack.go @@ -48,6 +48,13 @@ func (h *hijackedIOStreamer) stream(ctx context.Context) error { outputDone := h.beginOutputStream(restoreInput) inputDone, detached := h.beginInputStream(restoreInput) + defer func() { + // Close the pipe after the outputStream had done. + if err := h.resp.CloseWrite(); err != nil { + logrus.Debugf("Couldn't send EOF: %s", err) + } + }() + select { case err := <-outputDone: return err @@ -167,11 +174,6 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan logrus.Debugf("Error sendStdin: %s", err) } } - - if err := h.resp.CloseWrite(); err != nil { - logrus.Debugf("Couldn't send EOF: %s", err) - } - close(inputDone) }()