[Bug]: Race conditions in `ContainersService`
I have done the following
- [x] I have searched the existing issues
- [x] If possible, I've reproduced the issue using the 'main' branch of this project
Steps to reproduce
For example:
- Create two containers with the same name simultaneously:
#!/bin/bash
bin/container system start &
sleep 2
bin/container delete test-race
bin/container create --name test-race ubuntu &
bin/container create --name test-race ubuntu &
wait
Current behavior
Error: internalError: "failed to create container" (cause: "unknown: "Error Domain=NSCocoaErrorDomain Code=516 ""vmlinux-6.12.28-153" couldn't be copied to "test-race" because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Users/Dmitry/Library/Application Support/com.apple.container/kernels/vmlinux-6.12.28-153, NSUserStringVariant=( Copy ), NSDestinationFilePath=/Users/Dmitry/Library/Application Support/com.apple.container/containers/test-race/kernel.bin, NSFilePath=/Users/Dmitry/Library/Application Support/com.apple.container/kernels/vmlinux-6.12.28-153, NSURL=file:///Users/Dmitry/Library/Application%20Support/com.apple.container/kernels/vmlinux-6.12.28-153, NSUnderlyingError=0xc790ec420 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}"") test-race
Expected behavior
Error: internalError: "failed to create container" (cause: "exists: "container already exists: test-race"")
The likely races that need to be fixed occur in methods:
create()createProcess()stop()delete()_cleanup()
The following methods are likely safe:
list()kill()dial()wait()resize()cleanup()
Environment
N/A
Relevant log output
N/A
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
It seems #721 resolves only 1 of 5 races in ContainersService.
I'd like to take on this issue.
EDIT: Sorry, just saw assignee
@alex-trm go for it
@dkovba Closing this, it looks like it works now. I put your commands in a shell script here:
% ./container-race.sh
Warning! Running debug build. Performance may be degraded.
Verifying apiserver is running...
Warning! Running debug build. Performance may be degraded.
Error: notFound: "failed to delete one or more containers: ["test-race"]"
Warning! Running debug build. Performance may be degraded.
Warning! Running debug build. Performance may be degraded.
test-race
Error: internalError: "failed to create container" (cause: "exists: "container already exists: test-race"")
% ./container-race.sh
Warning! Running debug build. Performance may be degraded.
Verifying apiserver is running...
Warning! Running debug build. Performance may be degraded.
test-race
Warning! Running debug build. Performance may be degraded.
Warning! Running debug build. Performance may be degraded.
test-race
Error: internalError: "failed to create container" (cause: "exists: "container already exists: test-race"")
% ./container-race.sh
Warning! Running debug build. Performance may be degraded.
Verifying apiserver is running...
Warning! Running debug build. Performance may be degraded.
test-race
Warning! Running debug build. Performance may be degraded.
Warning! Running debug build. Performance may be degraded.
test-race
Error: internalError: "failed to create container" (cause: "exists: "container already exists: test-race"")