Skip to content

Commit

Permalink
Merge pull request moby#48334 from 7sunarni/master
Browse files Browse the repository at this point in the history
feat(stream): log the event when stream copy failed
  • Loading branch information
thaJeztah authored Aug 19, 2024
2 parents 0d0d4ee + cd148d3 commit 5efbb60
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions container/stream/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,35 @@ func (c *Config) CopyToPipe(iop *cio.DirectIO) {
ctx := context.TODO()

c.dio = iop
copyFunc := func(w io.Writer, r io.ReadCloser) {
copyFunc := func(name string, w io.Writer, r io.ReadCloser) {
c.wg.Add(1)
go func() {
if _, err := pools.Copy(w, r); err != nil {
log.G(ctx).Errorf("stream copy error: %v", err)
log.G(ctx).WithFields(log.Fields{"stream": name, "error": err}).Error("copy stream failed")
}
if err := r.Close(); err != nil {
log.G(ctx).WithFields(log.Fields{"stream": name, "error": err}).Warn("close stream failed")
}
r.Close()
c.wg.Done()
}()
}

if iop.Stdout != nil {
copyFunc(c.Stdout(), iop.Stdout)
copyFunc("stdout", c.Stdout(), iop.Stdout)
}
if iop.Stderr != nil {
copyFunc(c.Stderr(), iop.Stderr)
copyFunc("stderr", c.Stderr(), iop.Stderr)
}

if stdin := c.Stdin(); stdin != nil {
if iop.Stdin != nil {
go func() {
pools.Copy(iop.Stdin, stdin)
_, err := pools.Copy(iop.Stdin, stdin)
if err != nil {
log.G(ctx).WithFields(log.Fields{"stream": "stdin", "error": err}).Error("copy stream failed")
}
if err := iop.Stdin.Close(); err != nil {
log.G(ctx).Warnf("failed to close stdin: %v", err)
log.G(ctx).WithFields(log.Fields{"stream": "stdin", "error": err}).Warn("close stream failed")
}
}()
}
Expand Down

0 comments on commit 5efbb60

Please sign in to comment.