mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix race on sending stdin close event
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
9326fb1389
commit
4e262f6387
2 changed files with 35 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -4849,3 +4850,32 @@ func (s *DockerSuite) TestRunEmptyEnv(c *check.C) {
|
||||||
c.Assert(err, checker.NotNil)
|
c.Assert(err, checker.NotNil)
|
||||||
c.Assert(out, checker.Contains, expectedOutput)
|
c.Assert(out, checker.Contains, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #28658
|
||||||
|
func (s *DockerSuite) TestSlowStdinClosing(c *check.C) {
|
||||||
|
name := "testslowstdinclosing"
|
||||||
|
repeat := 3 // regression happened 50% of the time
|
||||||
|
for i := 0; i < repeat; i++ {
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "--rm", "--name", name, "-i", "busybox", "cat")
|
||||||
|
cmd.Stdin = &delayedReader{}
|
||||||
|
done := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
_, err := runCommand(cmd)
|
||||||
|
done <- err
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-time.After(15 * time.Second):
|
||||||
|
c.Fatal("running container timed out") // cleanup in teardown
|
||||||
|
case err := <-done:
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type delayedReader struct{}
|
||||||
|
|
||||||
|
func (s *delayedReader) Read([]byte) (int, error) {
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
|
|
@ -116,12 +116,16 @@ func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio
|
||||||
stdinOnce.Do(func() { // on error from attach we don't know if stdin was already closed
|
stdinOnce.Do(func() { // on error from attach we don't know if stdin was already closed
|
||||||
err = stdin.Close()
|
err = stdin.Close()
|
||||||
go func() {
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-ready:
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case <-ready:
|
case <-ready:
|
||||||
if err := ctr.sendCloseStdin(); err != nil {
|
if err := ctr.sendCloseStdin(); err != nil {
|
||||||
logrus.Warnf("failed to close stdin: %+v", err)
|
logrus.Warnf("failed to close stdin: %+v", err)
|
||||||
}
|
}
|
||||||
case <-ctx.Done():
|
default:
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue