cli icon indicating copy to clipboard operation
cli copied to clipboard

/cli/command/container/hijack.go: fix tcp half-closed connection unreliability in WSL

Open VertexToEdge opened this issue 2 years ago • 7 comments

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.

image

- How to verify it before: image

after: image

- 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)

VertexToEdge avatar Aug 31 '23 05:08 VertexToEdge

Codecov Report

Merging #4548 (2e01d90) into master (5777c1b) will decrease coverage by 0.04%. The diff coverage is 0.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     

codecov-commenter avatar Aug 31 '23 06:08 codecov-commenter

I figured out the real reason of bug. It is not race-condition. I updated it on this PR description. Thank you.

VertexToEdge avatar Sep 21 '23 13:09 VertexToEdge

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? 😅

thaJeztah avatar Sep 21 '23 14:09 thaJeztah

Oh sorry... Thanks for noticing. I will fix it in 15 hours.

VertexToEdge avatar Sep 21 '23 15:09 VertexToEdge

@laurazard are you able to help review this one? 🤗

thaJeztah avatar Oct 25 '23 21:10 thaJeztah

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

thaJeztah avatar Dec 20 '23 22:12 thaJeztah

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.

dmcgowan avatar Dec 20 '23 23:12 dmcgowan