Skip to content

server: serialize the device ID allocation of the NICs of an instance - #14815

Open
jmsperu wants to merge 2 commits into
apache:mainfrom
jmsperu:fix-nic-deviceid-lock
Open

jmsperu wants to merge 2 commits into
apache:mainfrom
jmsperu:fix-nic-deviceid-lock

Conversation

@jmsperu

@jmsperu jmsperu commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

NetworkOrchestrator.createNicForVm picked the free device ID of the instance and allocated the NIC without any lock. Networks added to the same instance at the same time (for example VPC tiers implemented in parallel, all plugged into the same VPC router) could all read the same free device ID, and the instance ended with several NICs on one device ID. On a VPC router this leaves tiers without a gateway while everything is reported as Implemented and Running.

This PR takes a lock per instance around the device ID pick and the NIC allocation. Nothing else changes.

Fixes #14814. Found while testing #14640, which fixes the Agent side of the same scenario; both are needed for parallel tier creation to be reliable.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • Major

How Has This Been Tested?

Lab test (CloudStack 4.22.1.1, 2 KVM hosts, one VPC with 6 tiers created and started in parallel, each run on a fresh VPC):

Phase Management server Agents Runs Runs with duplicate device IDs Runs with all 6 gateways up
A original with PR #14640 6 4 2
B this PR with PR #14640 8 0 8
C this PR original 3 0 0

Phase C shows the two changes are separate: with this PR alone the device IDs are always unique, but the original Agent still fails (3 to 4 NullPointerExceptions per run, 2, 5 and 3 gateways up), which is what PR #14640 fixes. Both are needed for a clean result. After the test the lab was put back on the original builds.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 20.83%. Comparing base (caf1091) to head (d29c4c6).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...tack/engine/orchestration/NetworkOrchestrator.java 95.23% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14815      +/-   ##
============================================
+ Coverage     20.80%   20.83%   +0.02%     
- Complexity    20925    20978      +53     
============================================
  Files          6053     6054       +1     
  Lines        548466   549025     +559     
  Branches      73283    73366      +83     
============================================
+ Hits         114129   114401     +272     
- Misses       420977   421229     +252     
- Partials      13360    13395      +35     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.27% <95.23%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmsperu
jmsperu force-pushed the fix-nic-deviceid-lock branch from ed714ef to 811831c Compare November 24, 2026 05:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VPC router ends with several NICs on the same device ID when tiers are created in parallel

1 participant