Skip to content

quick duplicate creation and deletion of containers gives an error #2192

@tianyax

Description

@tianyax

Description

The error occurs when I quickly and repeatedly create and delete containers, this error is occasional. In most cases, the error is:level=fatal msg="name \"redis\" is already used by ID \"add9d7fc0347f739632908ee28fb0387c37649f152b72987b36607839e86de95\"", and sometimes the error is: level=fatal msg="OCI runtime start failed: cannot start a container that has stopped: unknown"

Steps to reproduce the issue

func RunCmdAndWait(name string, args ...string) (string, error) {
	cmd := exec.Command(name, args...)

	stdout, _ := cmd.StdoutPipe()
	stderr, _ := cmd.StderrPipe()

	if err = cmd.Start(); err != nil {
		return "", err
	}

	errB, err := io.ReadAll(stderr)
	if err != nil {
		return "", err
	}

	resp, err := io.ReadAll(stdout)
	if err != nil {
		return "", err
	}

	if err := cmd.Wait(); err != nil {
		if len(errB) > 0 {
			return "", errors.New(string(errB))
		}
		return "", err
	}

	return string(resp), nil
}

func main() {
	for i := 0; i < 50; i++ {
		RunCmdAndWait("nerdctl", "rm", "-f", "redis")
		_, err := RunCmdAndWait("nerdctl", "run", "-d", "--name", "redis", "--restart", "always", "redis")
		if err != nil {
			fmt.Println(err)
			break
		}
	}
}

...
time="2023-04-19T17:04:09+08:00" level=fatal msg="name \"redis\" is already used by ID \"93eee71cf69efc9494436192869015820890ebfe4db6ef8712d9fb9f63f33ce1\""

Using the command method has the same problem

shell:

for _ in $(seq 1 50)
do
   nerdctl rm -f redis
   nerdctl run -d --name redis --restart always redis
done

...
ERRO[0000] multiple IDs found with provided prefix: redis 
FATA[0000] name "redis" is already used by ID "8b38cc634c8ceec79c7d3ec479e53c5efd85bdf48ef394e7f51754269d794d56" 

Describe the results you received and expected

Expect no errors.

What version of nerdctl are you using?

🔥 nerdctl version
Client:
 Version:	1.3.1
 OS/Arch:	linux/amd64
 Git commit:	<unknown>
 buildctl:
  Version:	0.11.5
  GitCommit:	alpine

Server:
 containerd:
  Version:	v1.7.0
  GitCommit:	1fbd70374134b891f97ce19c70b6e50c7b9f4e0d
 runc:
  Version:	1.1.6
  GitCommit:	0f48801a0e21e3f0bc4e74643ead2a502df4818d

Are you using a variant of nerdctl? (e.g., Rancher Desktop)

None

Host information

🔥 nerdctl info                                                                                                                                         Client:
 Namespace:	default
 Debug Mode:	false

Server:
 Server Version: v1.7.0
 Storage Driver: overlayfs
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Log: fluentd journald json-file syslog
  Storage: native overlayfs
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 6.1.23-4-lts
 Operating System: Alpine Linux edge
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.41GiB
 Name: x
 ID: dd8788c1-a4a7-4fd2-8768-a7422ba8bb08

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions