Skip to content

Store published ports as a sorted Vec instead of a BTreeSet#139

Merged
flowzone-app[bot] merged 1 commit into
mainfrom
compose-ports-cleanup
Jul 20, 2026
Merged

Store published ports as a sorted Vec instead of a BTreeSet#139
flowzone-app[bot] merged 1 commit into
mainfrom
compose-ports-cleanup

Conversation

@pipex

@pipex pipex commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

This simplifies the internal storage of ports to avoid the need for additional data structures. Ports are now sorted during target state validation and stored internally in the state as a Vec. They are also sorted when reading them from the engine. This ensures round-trip consistency, avoiding container recreation due to a port re-ordering on input.

Change-type: patch

@pipex
pipex force-pushed the compose-ports-cleanup branch from ec72178 to a11c577 Compare July 15, 2026 18:48
@flowzone-app
flowzone-app Bot enabled auto-merge July 15, 2026 19:15
@pipex
pipex force-pushed the compose-ports-cleanup branch 2 times, most recently from 75e9c3f to ceeb547 Compare July 15, 2026 23:58
@pipex
pipex requested a review from cywang117 July 15, 2026 23:58
Comment thread helios-oci/src/ports.rs Outdated
// `PortMap` is a hash map, so iteration order is unstable. Sort by
// container port then protocol to match the canonical order the target
// state uses, so a reordering never triggers reconfiguration.
ports.sort_by_key(|p| (p.target, p.protocol));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be safer to include the other port fields in the sort to ensure stable ordering?

@pipex pipex Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is already stable no, a composition defining the same port/protocol twice should perhaps be invalid?

Disregard that, I think you are right

Comment thread helios-oci/src/ports.rs
/// for a container create request. Multiple mappings of the same container
/// port/protocol are grouped into a single binding list.
pub(crate) fn to_oci_port_maps(ports: BTreeSet<PortMapping>) -> (Vec<String>, PortMap) {
pub(crate) fn to_oci_port_maps(ports: Vec<PortMapping>) -> (Vec<String>, PortMap) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By changing the data structure to a Vec, isn't dedupe capability lost? So a repeated port entry in a call to helios (doable from local endpoint only) would result in a target state apply loop no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The previous dedupe was not correct either, a composition defining

- 8080:80
- target: 80
  published: 8080
  host_ip: 127.0.0.1

would still be allowed even if ambiguous. I'm unsure if to reject this case or go with the last definition in the given order

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Docker compose doesn't validate the scenario above, it just terminates with failed to bind host port 127.0.0.1:8080/tcp: address already in use

@pipex pipex Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added a dedup() step on target state processing to remove exact duplicate configurations but keep the docker behavior wrt ambiguous definitions.

This simplifies the internal storage of ports to avoid the need for
additional data structures. Ports are now sorted during target state
validation and stored internally in the state as a Vec. They are also
sorted when reading them from the engine. This ensures round-trip
consistency, avoiding container recreation due to a port re-ordering on
input.

Change-type: patch
@pipex
pipex force-pushed the compose-ports-cleanup branch from ceeb547 to fece8e9 Compare July 17, 2026 16:11

@cywang117 cywang117 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@flowzone-app
flowzone-app Bot merged commit 519b9fc into main Jul 20, 2026
58 of 59 checks passed
@flowzone-app
flowzone-app Bot deleted the compose-ports-cleanup branch July 20, 2026 15:45
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.

2 participants