/cli/command/container/hijack.go: fix tcp half-closed connection unreliability in WSL
closes #3586
- What I did I fixed tcp half-closed connection unreliability. the problem occurs because of half-closeing hijacked socket. it makes tcp connection closed.
I experimented various of situation(windows<->ubuntu, windows<->hyper-v ubuntu, windows <-> hyper-v windows). but only windows -> WSL(linux) cannot make half-closed connection that is host to guest direction.
- How I did it
I moved h.resp.CloseWrite() to func (h *hijackedIOStreamer) stream(ctx context.Context) error from goroutine in func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan struct{}, detachedC <-chan error)
It secures hijacked socket will send and receive all of data. so it prevents half-closed connection in attach sequence.
- How to verify it
before:
after:
- Description for the changelog Fixed no output of docker run command over WSL 2 Docker context from Windows via tcp
- A picture of a cute animal (not mandatory but encouraged)
Codecov Report
Merging #4548 (2e01d90) into master (5777c1b) will decrease coverage by
0.04%. The diff coverage is0.00%.
Additional details and impacted files
@@ Coverage Diff @@
## master #4548 +/- ##
==========================================
- Coverage 59.68% 59.65% -0.04%
==========================================
Files 287 285 -2
Lines 24752 24751 -1
==========================================
- Hits 14774 14765 -9
- Misses 9092 9098 +6
- Partials 886 888 +2
I figured out the real reason of bug. It is not race-condition. I updated it on this PR description. Thank you.
Thanks! I asked a colleague who's more familiar with some of this to have a look (but they're on leave currently, so hope they get round to it).
I did notice there's a typo in the commit message (commnad instead of command) if you need to do another update of the PR, could you fix that? 😅
Oh sorry... Thanks for noticing. I will fix it in 15 hours.
@laurazard are you able to help review this one? 🤗
Looks like this one dropped between the cracks. I did a quick rebase to get a run of CI, and will try to get reviewers
I fixed tcp half-closed connection unreliability. the problem occurs because of half-closeing hijacked socket. it makes tcp connection closed.
Isn't the problem then that CloseWrite is closing the stream, not when CloseWrite is called. Write should always be closed after all writes are completed so that the other end of the stream can get the EOF signal and complete its write. Calling CloseWrite after done reading could cause deadlock situations where both ends of the stream are waiting on each other. A basic example would be cat stdio to stdout. It seems that if there is an issue, its in the implementation of CloseWrite rather than it being called incorrectly.