Always Cancel before Close

Document this contract.

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin 2017-12-07 16:03:00 -05:00
parent 31dabf0c7d
commit 65665ab807
3 changed files with 6 additions and 3 deletions

View File

@ -24,11 +24,12 @@ type Config struct {
type IO interface {
// Config returns the IO configuration.
Config() Config
// Cancel aborts all current io operations
// Cancel aborts all current io operations.
Cancel()
// Wait blocks until all io copy operations have completed
// Wait blocks until all io copy operations have completed.
Wait()
// Close cleans up all open io resources
// Close cleans up all open io resources. Cancel() is always called before
// Close()
Close() error
}

View File

@ -191,6 +191,7 @@ func (p *process) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitS
return nil, errdefs.FromGRPC(err)
}
if p.io != nil {
p.io.Cancel()
p.io.Wait()
p.io.Close()
}

View File

@ -163,6 +163,7 @@ func (t *task) Start(ctx context.Context) error {
ContainerID: t.id,
})
if err != nil {
t.io.Cancel()
t.io.Close()
return errdefs.FromGRPC(err)
}