Skip to content
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

port forward range test: fix an oops #14855

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

edsantiago
Copy link
Member

Wrong variable.

Fixes: #14854

Signed-off-by: Ed Santiago [email protected]

None

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 7, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 7, 2022
@rhatdan
Copy link
Member

rhatdan commented Jul 7, 2022

LGTM
@containers/podman-maintainers PTAL

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 7, 2022
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2022
Comment on lines 680 to 681
local port="${range%-*}"
local end_port="${range#-*}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Luap99 PTAL. The obvious question is, how did this ever work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It simply did not work. We just never looped in for port.

But this is not even the actual problem I was reporting. The test picked 5354-5356 which is wrong, 5355 is always blocked. So the free port logic has a bug as well.

@edsantiago
Copy link
Member Author

Testing this on my laptop, rootless, I'm reliably getting:

$ bin/podman run --network bridge -p 5933-5955:5933-5955 -d quay.io/libpod/testimage:20220615 top
Error: failed to mount runtime directory for rootless netns: no such file or directory

Looks like #13703, but this is f36, and it's not an SELinux issue (fails with setenforce 0). This morning's dnf upgrade brought in a new glibc, could that be it?

@Luap99
Copy link
Member

Luap99 commented Jul 7, 2022

Testing this on my laptop, rootless, I'm reliably getting:

$ bin/podman run --network bridge -p 5933-5955:5933-5955 -d quay.io/libpod/testimage:20220615 top
Error: failed to mount runtime directory for rootless netns: no such file or directory

Looks like #13703, but this is f36, and it's not an SELinux issue (fails with setenforce 0). This morning's dnf upgrade brought in a new glibc, could that be it?

That error can happen because of many different reasons. Try to cleanup the netns rm -f $XDG_RUNTIME_DIR/netns/rootless-netns*

@edsantiago
Copy link
Member Author

Thanks, that fixed it. I wonder if the error message could be fixed so it offers that command (rm -f ...) as a suggestion? That will be helpful to people who get that error message without having a clue what happened or how to fix it. Like me.

@Luap99
Copy link
Member

Luap99 commented Jul 7, 2022

Thanks, that fixed it. I wonder if the error message could be fixed so it offers that command (rm -f ...) as a suggestion? That will be helpful to people who get that error message without having a clue what happened or how to fix it. Like me.

Well there are downsides to this, for testing it is fine but in production you should not do it. The problem is that without the namespace newly started containers can not talk to containers started before you removed it.

This whole thing is fragile and needs to be improved. Podman should be able to recover from this on its own without user intervention.

@Luap99
Copy link
Member

Luap99 commented Jul 7, 2022

@edsantiago I think we also need:

diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index 273e8d2f5..e4d44c4a9 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -300,7 +300,7 @@ function random_free_port_range() {
     while [[ $maxtries -gt 0 ]]; do
         local firstport=$(random_free_port)
         local all_ports_free=1
-        for i in $(seq 2 $size); do
+        for i in $(seq 1 $(($size - 1))); do
             if ! port_is_free $((firstport + $i)); then
                 all_ports_free=
                 break

right now it tests port, port + 2, port + 3 so it failed to check port + 1

@edsantiago
Copy link
Member Author

Yes, but there's also something else seriously broken. The whole exec /dev/tcp thing is completely broken. I'm trying to figure out why.

Wrong variable. And, wrong index range. And, wrong bash
syntax for extracting end_port. And, add explicit check
for valid range, because die() inside 'foo=$(...)' will not
actually die. And, refactor some confusing code. And,
reformat/clean up a confusing and too-wide comment.

Fixes: containers#14854

Signed-off-by: Ed Santiago <[email protected]>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2022
@edsantiago
Copy link
Member Author

This blew up. New changes are much, much more complicated than originally intended. However, the end result is IMO cleaner.

@@ -677,16 +677,20 @@ EOF
@test "podman run port forward range" {
for netmode in bridge slirp4netns:port_handler=slirp4netns slirp4netns:port_handler=rootlesskit; do
local range=$(random_free_port_range 3)
local port="${test%-*}"
local end_port="${test#-*}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUBTLE BUT IMPORTANT! Note the change of dash-asterisk to asterisk-star in this one!

@Luap99
Copy link
Member

Luap99 commented Jul 7, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2022
@edsantiago
Copy link
Member Author

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 7, 2022
@openshift-ci openshift-ci bot merged commit 41ac2cf into containers:main Jul 7, 2022
@edsantiago edsantiago deleted the port_forward_duh branch July 7, 2022 17:42
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test/system: podman run port forward range problem
4 participants