Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cmd/containerd-shim-runhcs-v1/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,24 @@ func trapClosedConnErr(err error) error {
// readOptions reads in bytes from the reader and converts it to a shim options
// struct. If no data is available from the reader, returns (nil, nil).
func readOptions(r io.Reader) (*runhcsopts.Options, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

readDone := make(chan struct{})
go func() {
select {
case <-ctx.Done():
// Forcefully break the blocking io.ReadAll if the daemon disconnects
if c, ok := r.(io.Closer); ok {
c.Close()
}
case <-readDone:
// Read completed successfully, exit the monitor
}
}()

d, err := io.ReadAll(r)
close(readDone)
if err != nil {
return nil, errors.Wrap(err, "failed to read input")
}
Expand Down