Conversation
…rved IP allocation eql? delegated to == which loses CIDR prefix via IPAddr#coerce_other, causing eql?/hash to disagree and making Set dedup non-deterministic. Fix both to include prefix. Also change sort key to [to_i, prefix] so larger blocks always precede the /32s they contain, ensuring find_next_available_ip skips entire reserved ranges.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/bosh-director/lib/bosh/director/ip_addr_or_cidr.rb`:
- Around line 47-51: The equality and hash implementations in IpAddrOrCidr
ignore address family causing IPv4 and IPv6 addresses with the same
integer/prefix to collide; update the eql? method (the equality check that
currently compares `@ipaddr.to_i` and `@ipaddr.prefix`) to also compare the address
family (e.g., `@ipaddr.family` or using ipv4?/ipv6?) and change the hash method to
include the same family value (e.g., include `@ipaddr.family` in the array used to
compute the hash) so that family is part of both equality and hashing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0554b280-a5ef-4ddc-8135-62fbc2037f04
📒 Files selected for processing (3)
src/bosh-director/lib/bosh/director/deployment_plan/ip_provider/ip_repo.rbsrc/bosh-director/lib/bosh/director/ip_addr_or_cidr.rbsrc/bosh-director/spec/unit/bosh/director/ip_addr_or_cidr_spec.rb
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/bosh-director/spec/unit/bosh/director/ip_addr_or_cidr_spec.rb`:
- Around line 293-304: The test is using different prefixes (/32 vs /128) so
failure could be due to prefix mismatch rather than address family; update the
two examples to use the same prefix to isolate family as the cause. In the spec
examples that create IpAddrOrCidr objects (IpAddrOrCidr.new('0.0.0.1/32') and
IpAddrOrCidr.new('::1/128')), change the IPv6 case to use the same prefix (e.g.
IpAddrOrCidr.new('::1/32')), then keep the assertions on ipv4.eql?(ipv6) being
false and Set.new([ipv4, ipv6]).size eq(2) to verify distinctness by family.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 9a842170-4b3f-4c7b-9b64-5d586ba51b86
📒 Files selected for processing (2)
src/bosh-director/lib/bosh/director/ip_addr_or_cidr.rbsrc/bosh-director/spec/unit/bosh/director/ip_addr_or_cidr_spec.rb
|
Excited for this fix to land! I've seen a few flakes locally and now seeing one in GHA |
What is this change about?
Follow-up fix to #2657 to eliminate residual flaky behaviour in IP allocation from reserved CIDR ranges.
PR #2657 fixed the algorithmic logic in
find_next_available_ip(pruning by last address, usingoverlaps?, capturingblocking_ipbefore mutation). However, the very second test run in Concourse failed. It looks like the issue is still present under certain Ruby hash seeds:Changes:
IpAddrOrCidr#eql?: now compares bothto_iandprefixdirectly, treating objects with the same base address but different prefix lengths as distinctIpAddrOrCidr#hash: now uses[to_i, prefix].hashto satisfy the contractfind_next_available_ipsort key: changed fromip.to_ito[ip.to_i, ip.prefix]so larger blocks (smaller prefix) always sort before the/32s they containPlease provide contextual information.
What tests have you run against this PR?
IpAddrOrCidrunit specs pass (spec/unit/bosh/director/ip_addr_or_cidr_spec.rb)IpRepounit specs pass, including the CIDR block tests added by Fix IP Allocation Bug: Reserved Range Not Detected #2657 (spec/unit/bosh/director/deployment_plan/ip_provider/ip_repo_spec.rb)#eql?and#hashcovering:eql?true, equal hashes, deduplicates in Seteql?false, different hashes, coexist as distinct Set elementseql?falseHow should this change be described in bosh release notes?
Fixed: IP allocation could intermittently assign addresses from reserved CIDR ranges due to non-deterministic Set behaviour in the IP dedup logic.
Does this PR introduce a breaking change?
No. This is a bug fix. The observable behaviour - that IPs are not allocated from reserved ranges - is unchanged; the fix makes it deterministic.