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

Fix issue with conflicting ports when starting multiple Dev sessions on Podman #6660

Conversation

rm3l
Copy link
Member

@rm3l rm3l commented Mar 14, 2023

What type of PR is this:
/kind bug
/area odo-on-podman

What does this PR do / why we need it:
Due to regression on 6.1+ kernels [1], binding on 127.0.0.1:$port after some process listens on 0.0.0.0:$port does pass, which is not expected. Until this issue is fixed [2], a possible workaround is to try to bind on 0.0.0.0:$port. This works correctly on Podman, and also on Kubernetes (because we do port-forwarding on Kubernetes on 127.0.0.1:$port).

The unit test added should allow us to detect similar issues faster in the future, should it happen again.

[1] https://lore.kernel.org/stable/e21bf153-80b0-9ec0-15ba-e04a4ad42c34@redhat.com/T/
[2] https://lore.kernel.org/netdev/20230312031904.4674-3-kuniyu@amazon.com/T/

Which issue(s) this PR fixes:
Fixes #6612

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:
See the repro steps provided in #6612

…on Podman

Due to regression on 6.1+ kernels [1], binding on 127.0.0.1:$port after some process
listens on 0.0.0.0:$port does pass, which is not expected.
Until this issue is fixed [2], a possible workaround is to try to bind on 0.0.0.0:$port.
This works correctly on Podman, and also on Kubernetes
(because we do port-forwarding on Kubernetes on 127.0.0.1:$port).

The unit test added should allow us to detect similar issues faster in the future,
should it happen again.

[1] https://lore.kernel.org/stable/e21bf153-80b0-9ec0-15ba-e04a4ad42c34@redhat.com/T/
[2] https://lore.kernel.org/netdev/20230312031904.4674-3-kuniyu@amazon.com/T/
@netlify
Copy link

netlify bot commented Mar 14, 2023

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit 452d1cc
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/641058558b7e41000861f2c8

@openshift-ci openshift-ci bot added kind/bug Categorizes issue or PR as related to a bug. area/odo-on-podman Issues or PRs related to running odo against Podman labels Mar 14, 2023
@rm3l rm3l requested a review from feloy March 14, 2023 11:21
@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

OpenShift Unauthenticated Tests on commit be74f9a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

NoCluster Tests on commit be74f9a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

Unit Tests on commit be74f9a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

Validate Tests on commit be74f9a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

Kubernetes Tests on commit be74f9a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

Windows Tests (OCP) on commit be74f9a finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

OpenShift Tests on commit be74f9a finished successfully.
View logs: TXT HTML

listener, err := net.Listen("tcp", address)
if err != nil {
return false
}
_ = listener.Addr().(*net.TCPAddr).Port
Copy link
Contributor

Choose a reason for hiding this comment

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

What did this do?

Copy link
Member Author

@rm3l rm3l Mar 14, 2023

Choose a reason for hiding this comment

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

It can be used to determine the port value on which we are listening (by casting listener.Addr() into *net.TCPAddr). But the return value is not used at all. And it is useless to me since we are already passing the input port to net.Listen. It would have been useful for example if we were letting the kernel bind to a random port and we wanted to get that random port value.

@@ -782,12 +782,11 @@ func SafeGetBool(b *bool) bool {

// IsPortFree checks if the port on localhost is free to use
func IsPortFree(port int) bool {
address := fmt.Sprintf("localhost:%d", port)
address := fmt.Sprintf("0.0.0.0:%d", port)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this change be reverted once the regression has been fixed? If so, can you add a todo about it?

Copy link
Member Author

@rm3l rm3l Mar 14, 2023

Choose a reason for hiding this comment

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

To me, this is still valid even after the regression is fixed in the kernel. Podman binds by default to 0.0.0.0, so it makes sense to check on all addresses. As for Kubernetes, port-forwarding currently binds to 127.0.0.1 by default, but it makes sense to me to still check on all addresses.
As part of #6479, we would need to properly control the address on which to bind and pass the right address to this function.

@rm3l rm3l closed this Mar 16, 2023
@rm3l rm3l reopened this Mar 16, 2023
@sonarcloud
Copy link

sonarcloud bot commented Mar 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@odo-robot
Copy link

odo-robot bot commented Mar 16, 2023

Kubernetes Docs Tests on commit 8f9ced9 finished successfully.
View logs: TXT HTML

Copy link
Contributor

@feloy feloy left a comment

Choose a reason for hiding this comment

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

Thanks for this fix

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Mar 20, 2023
@openshift-merge-robot openshift-merge-robot merged commit 86b271d into redhat-developer:main Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/odo-on-podman Issues or PRs related to running odo against Podman kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot start 2 different Dev sessions on Podman due to conflicting host ports
4 participants