syncpipe: read from parent before reporting error

Docker-DCO-1.1-Signed-off-by: Bernerd Schaefer <bj.schaefer@gmail.com> (github: bernerdschaefer)
This commit is contained in:
Bernerd Schaefer 2014-08-29 16:17:22 +02:00
parent 4080743cbc
commit 1faa2b56df
2 changed files with 15 additions and 2 deletions

View File

@ -77,6 +77,10 @@ func (s *SyncPipe) ReadFromParent(v interface{}) error {
}
func (s *SyncPipe) ReportChildError(err error) {
// ensure that any data sent from the parent is consumed so it doesn't
// receive ECONNRESET when the child writes to the pipe.
ioutil.ReadAll(s.child)
s.child.Write([]byte(err.Error()))
s.CloseChild()
}

View File

@ -2,6 +2,7 @@ package syncpipe
import (
"fmt"
"syscall"
"testing"
)
@ -20,9 +21,17 @@ func TestSendErrorFromChild(t *testing.T) {
}
}()
expected := "something bad happened"
childfd, err := syscall.Dup(int(pipe.Child().Fd()))
if err != nil {
t.Fatal(err)
}
childPipe, _ := NewSyncPipeFromFd(0, uintptr(childfd))
pipe.ReportChildError(fmt.Errorf(expected))
pipe.CloseChild()
pipe.SendToChild(nil)
expected := "something bad happened"
childPipe.ReportChildError(fmt.Errorf(expected))
childError := pipe.ReadFromChild()
if childError == nil {