Skip to content

Fix stdout premature EOF#8571

Merged
jessfraz merged 1 commit intomoby:masterfrom
ncdc:3631-stdout-premature-eof
Oct 29, 2014
Merged

Fix stdout premature EOF#8571
jessfraz merged 1 commit intomoby:masterfrom
ncdc:3631-stdout-premature-eof

Conversation

@ncdc
Copy link
Copy Markdown
Contributor

@ncdc ncdc commented Oct 14, 2014

Never close attached stream before both stdout and stderr have written
all their buffered contents. Remove stdinCloser because it is not needed
any more as the stream is closed anyway after attach has finished.

Fixes #3631

Signed-off-by: Andy Goldstein [email protected]

@ncdc ncdc mentioned this pull request Oct 14, 2014
Comment thread builder/internals.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LK4D4 didn't you already change this to use logs?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not merged for now

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 14, 2014

Do you all generally prefer the nJobs for loop that currently exists in master, or the 2 "done" booleans with the break statement?

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 14, 2014

Actually, scratch that, since we have to wait for stdout and stderr to finish before we can close stdin

@ncdc ncdc force-pushed the 3631-stdout-premature-eof branch from d188761 to 8fc8703 Compare October 14, 2014 20:49
@tonistiigi
Copy link
Copy Markdown
Member

@ncdc I'm slightly in favor of keeping the nJobs loop but like the removal of stdinCloser very much if it doesn't change any behavior(I can't see how it could). There's some added confusion with the name stdinCloser as it has almost nothing to do with process stdin. To rephrase your last comment: we have to wait for stdout and stderr to finish before we can close the attached stream

ping @creack as it seems to be introduced in #329

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 15, 2014

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 15, 2014

Oh, that won't work as-is, because if you do

docker run --rm -it fedora bash
exit

it will hang waiting for the stdin job to complete. If you hit enter, it will finish and return you to the host's shell.

I think we need to finish attach when either all 3 jobs have finished, or both stdout and stderr have finished, whichever happens first. Something more like this: https://github.com/ncdc/docker/compare/3631-stdout-premature-eof-njobs-2

Comment thread daemon/attach.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all stuff seems to be in different goroutines, so this code is racy, probably you should use channels for this notifications.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll work on it tomorrow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now better, so you want to save nJobs idea? I think it will be better to just write stdout job finished or something like this. Maybe in addition to number...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine getting rid of nJobs if everyone is ok with that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's ask someone. ping @jfrazelle @erikh

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonistiigi
Copy link
Copy Markdown
Member

@ncdc Can you explain the bash regression you were having with the previous version a bit more. I don't see any differences compared to v1.3.0 myself.

edit: also, just to be clear, what branch were you talking about?

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 21, 2014

@tonistiigi that was just from me fiddling around with nJobs. If all you do is get rid of the stdinCloser logic, the stdin job won't complete until the client closes its end of the stream, which happens when you hit enter after attempting to exit from the shell. If the client opens stdin, the engine needs to close its half of the stdin stream when stdout and stderr finish.

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 21, 2014

@tonistiigi and for clarity, the "regression" was in my branch

@tonistiigi
Copy link
Copy Markdown
Member

@ncdc ok, I though this was in 3631-stdout-premature-eof not 3631-stdout-premature-eof-njobs

Looking at 3631-stdout-premature-eof-njobs you have also removed stdin.Close() calls, not only stdinCloser(). This should cause the bash thing. I also don't understand the added cStdin.Close() in the end.

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Oct 22, 2014

@ncdc Would you mind to post your branch here?

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 22, 2014

@LK4D4 I'm currently attempting to write an integration test that fails with master but is fixed with my branch. I also think @tonistiigi might be on to something simpler - we maybe can just remove the stdinCloser concept altogether. I'll update this branch once things are closer to ready. Sound ok?

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Oct 22, 2014

Okay, keep us updated!

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 22, 2014

@LK4D4 this is the best I've been able to come up with so far for an integration test. I was hoping to imitate TestAttachMultipleAndRestart but for some reason the StdoutPipe would always get all the data.

func TestAttachSlowConsumer(t *testing.T) {                                         
  defer deleteAllContainers()                                                        

  c := exec.Command("/bin/bash", "-c", "echo | "+dockerBinary+` run --rm -i busybox /bin/sh -c "dd if=/dev/zero of=/foo bs=1024 count=2000 &>/dev/null; catv /foo" | /bin/bash -c "sleep 2; wc -c"`)

  output, err := c.Output()                                                          
  if err != nil {
    t.Fatal(err)
  } 

  // assert that output == 2*1024*2000

  logDone("attach - slow consumer")                                                 
} 

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Oct 22, 2014

I remember that @tibor wrote something cool with tty in tests. Maybe he can help.

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 22, 2014

I obviously don't like the sleep 2 in the test, but I don't currently know of a way to wait the exact amount of time required for the output stream to be closed prematurely, as the daemon is the only thing that's aware of that happening, and the attach job essentially swallows the error and returns an ok status regardless.

Also, once this issue is fixed, we won't exactly be able to wait for a "stream closed" error...

@ncdc ncdc force-pushed the 3631-stdout-premature-eof branch from 8fc8703 to ab2e935 Compare October 22, 2014 20:05
@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 22, 2014

@LK4D4 @tonistiigi PR updated, please see latest diffs.

Never close attached stream before both stdout and stderr have written
all their buffered contents. Remove stdinCloser because it is not needed
any more as the stream is closed anyway after attach has finished.

Fixes moby#3631

Signed-off-by: Andy Goldstein <[email protected]>
@tonistiigi
Copy link
Copy Markdown
Member

@ncdc LGTM

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Oct 23, 2014

Very good indeed!
LGTM

@ncdc
Copy link
Copy Markdown
Contributor Author

ncdc commented Oct 29, 2014

@LK4D4 do we need other reviews so this can hopefully be merged in?

@jessfraz
Copy link
Copy Markdown
Contributor

LGTM

jessfraz pushed a commit that referenced this pull request Oct 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stdout premature EOF

5 participants