Skip to content

Commit

Permalink
fix: ignore already in progress error
Browse files Browse the repository at this point in the history
  • Loading branch information
Haegi committed Jan 9, 2023
1 parent 7f3b016 commit a2b478c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
@@ -17,9 +17,11 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat"
"github.com/orlangure/gnomock/internal/cleaner"
"github.com/orlangure/gnomock/internal/health"
"github.com/pkg/errors"
"go.uber.org/zap"
)

@@ -442,8 +444,8 @@ func (d *docker) removeContainer(ctx context.Context, id string) error {
d.lock.Lock()
defer d.lock.Unlock()

err := d.client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{})
if err != nil && !client.IsErrNotFound(err) {
err := d.client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true})
if err != nil && !client.IsErrNotFound(err) && isDeletionAlreadyInProgessError(err, id) {
return fmt.Errorf("can't remove container %s: %w", id, err)
}

@@ -465,3 +467,9 @@ func (d *docker) hostAddr() string {

return localhostAddr
}

func isDeletionAlreadyInProgessError(err error, id string) bool {
return errors.Is(err, errdefs.Conflict(
errors.Wrap(fmt.Errorf("removal of container %s is already in progress", id),
"Error response from daemon")))
}

0 comments on commit a2b478c

Please sign in to comment.