-
Notifications
You must be signed in to change notification settings - Fork 649
[Bugfix] Check if port is used in publish flag [duplicate of #2190] #4097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
aaeb6ce
to
af654a8
Compare
4e10732
to
65feab1
Compare
Signed-off-by: Vishwas Siravara <vsiravara@gmail.com>
65feab1
to
002c0d4
Compare
The current implementation breaks in rootless mode which is resulting in the test failures. I am guessing this is mainly due to how Rootlesskit uses slirp4netns to create a separate net ns and possibly the port allocation information is no longer visible in /proc/net/*. We can either implement some mechanism to track the rootless state or may be add a generic port store to track all port usage. |
Rootless > 2.0 starts with a detached network namespace by default. You need to |
@@ -42,24 +42,56 @@ func filter(ss []procnet.NetworkDetail, filterFunc func(detail procnet.NetworkDe | |||
} | |||
|
|||
func portAllocate(protocol string, ip string, count uint64) (uint64, uint64, error) { | |||
netprocData, err := procnet.ReadStatsFileData(protocol) | |||
usedPort, err := getUsedPorts(ip, protocol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usedPort, err := getUsedPorts(ip, protocol) | |
usedPorts, err := getUsedPorts(ip, protocol) |
if err != nil { | ||
return 0, 0, err | ||
} | ||
netprocItems := procnet.Parse(netprocData) | ||
|
||
start := uint64(allocateStart) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make things simpler please declare allocateStart
and allocateEnd
with uint64
type
This PR continues the work from #2190 (originally by @vsiravar) which checks for used ports while allocating host port in -p/--publish. The original PR is already approved and was just waiting for a rebase form the author. Most of the comments have already been addressed.
Addressing port cleanup on stop:
The original PR had some open discussion around handling port cleanups on container stop
This is now already being addressed with this PR #2839 as network cleanup is part of both container stop and kill
Verified the fix:
Fixes: #2179
cc @fahedouch @vsiravar