Skip to content

Extend docker/net utils to allow port checks for UDP ports#7955

Merged
whummer merged 2 commits intomasterfrom
docker-ports-udp
Mar 28, 2023
Merged

Extend docker/net utils to allow port checks for UDP ports#7955
whummer merged 2 commits intomasterfrom
docker-ports-udp

Conversation

@whummer
Copy link
Member

@whummer whummer commented Mar 24, 2023

Extend docker/net utils to allow port checks for UDP ports. Addresses an issue from a support channel where starting up the LS container fails due to UDP port 53 already being bound.

This PR extends container_ports_can_be_bound(..) to allow us to make port availability checks also for UDP ports, which will allow us to selectively add the port bind for UDP port 53, based on availability.

Tried to make the changes minimally invasive, and backwards-compatible. Ports can be specified as an int (in which case we assume TCP as the default protocol), or as a Port instance that contains the protocol explicitly.

The existing TestDockerPorts test has been parameterized to also cover UDP ports, and a new simple test has been added to cover the UDP-based logic for port_can_be_bound(..).

Debatable whether this is a new feature or a fix 🤷 - but since it addresses a support case, arguably this could still be considered for the pre v2 merges (despite the feature freeze). To be discussed..

/cc @simonrw @dfangl

@whummer whummer requested a review from simonrw March 24, 2023 12:56
@coveralls
Copy link

Coverage Status

Coverage: 81.802% (-0.06%) from 81.867% when pulling abcde65 on docker-ports-udp into d4dbb0b on master.

@whummer whummer marked this pull request as ready for review March 24, 2023 14:12
Copy link
Contributor

@simonrw simonrw left a comment

Choose a reason for hiding this comment

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

Looks good, a minor suggestion about the API surface of localstack.utils.net but not blocking

port: int, http_path: str = None, expect_success=True, retries=10, sleep_time=0.5
):
"""Ping the given network port until it becomes available (for a given number of retries).
"""Ping the given TCP network port until it becomes available (for a given number of retries).
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the functions in this file could all be updated to take IntOrPort (or Port if they are not part of the public API), then the entire utility file would be protocol agnostic. What do you think? Perhaps an update for a future PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, agreed. Would probably leave that for a future iteration.. 👍

Copy link
Member

@dfangl dfangl left a comment

Choose a reason for hiding this comment

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

LGTM!

@whummer whummer merged commit 296a257 into master Mar 28, 2023
@whummer whummer deleted the docker-ports-udp branch March 28, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants