From 1faa2b56df20fe7700d8485742c2768e4b5b9d51 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Fri, 29 Aug 2014 16:17:22 +0200 Subject: [PATCH] syncpipe: read from parent before reporting error Docker-DCO-1.1-Signed-off-by: Bernerd Schaefer (github: bernerdschaefer) --- syncpipe/sync_pipe.go | 4 ++++ syncpipe/sync_pipe_test.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/syncpipe/sync_pipe.go b/syncpipe/sync_pipe.go index d2870f52..f73c354d 100644 --- a/syncpipe/sync_pipe.go +++ b/syncpipe/sync_pipe.go @@ -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() } diff --git a/syncpipe/sync_pipe_test.go b/syncpipe/sync_pipe_test.go index 6833277a..906e6ed2 100644 --- a/syncpipe/sync_pipe_test.go +++ b/syncpipe/sync_pipe_test.go @@ -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 {