Skip to content

Commit 65665ab

Browse files
committed
Always Cancel before Close
Document this contract. Signed-off-by: Daniel Nephin <dnephin@gmail.com>
1 parent 31dabf0 commit 65665ab

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

cio/io.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ type Config struct {
2424
type IO interface {
2525
// Config returns the IO configuration.
2626
Config() Config
27-
// Cancel aborts all current io operations
27+
// Cancel aborts all current io operations.
2828
Cancel()
29-
// Wait blocks until all io copy operations have completed
29+
// Wait blocks until all io copy operations have completed.
3030
Wait()
31-
// Close cleans up all open io resources
31+
// Close cleans up all open io resources. Cancel() is always called before
32+
// Close()
3233
Close() error
3334
}
3435

process.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func (p *process) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitS
191191
return nil, errdefs.FromGRPC(err)
192192
}
193193
if p.io != nil {
194+
p.io.Cancel()
194195
p.io.Wait()
195196
p.io.Close()
196197
}

task.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (t *task) Start(ctx context.Context) error {
163163
ContainerID: t.id,
164164
})
165165
if err != nil {
166+
t.io.Cancel()
166167
t.io.Close()
167168
return errdefs.FromGRPC(err)
168169
}

0 commit comments

Comments
 (0)