dotnetcore/CAP · error · Exception
no available mac found
Error message
no available mac found
What it means
A hardware-environment guard in SnowflakeId's MAC-based worker-id generation: GenerateWorkerIdBaseOnMac iterates network interfaces excluding virtual and loopback adapters, and when none qualifies (e.g. containers/VMs exposing only virtual NICs, or no network hardware) the method reports that no usable MAC address exists to derive a worker id from. It is raised inside worker-id auto-detection, not during message flow.
Solutions
- Set SnowflakeIdOptions.WorkerId explicitly to a stable value in the 0–1023 range so MAC detection is never needed.
- In containerized environments where only virtual adapters exist, prefer explicit configuration or an external id allocator over MAC-based auto-detection.
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at src/DotNetCore.CAP/Internal/ISnowflakeId.Default.cs:162 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14).
Data as JSON: /api/errors/444c5728b4db2745.
Report an issue: GitHub.
Appendix: source
Thrown at src/DotNetCore.CAP/Internal/ISnowflakeId.Default.cs:162
}
catch
{
return GenerateRandomWorkerId(maxWorkerId);
}
}
/// <summary>
/// use lowest 10 bit of available MAC as workerId
/// </summary>
/// <returns>workerId</returns>
private static long GenerateWorkerIdBaseOnMac()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
//exclude virtual and Loopback
var firstUpInterface = nics.OrderByDescending(x => x.Speed).FirstOrDefault(x =>
!x.Description.Contains("Virtual") && x.NetworkInterfaceType != NetworkInterfaceType.Loopback &&
x.OperationalStatus == OperationalStatus.Up);
if (firstUpInterface == null) throw new Exception("no available mac found");
var address = firstUpInterface.GetPhysicalAddress();
var mac = address.GetAddressBytes();
return ((mac[4] & 0B11) << 8) | (mac[5] & 0xFF);
}
/// <summary>
/// randomly generate one as workerId
/// </summary>
/// <returns></returns>
private static long GenerateRandomWorkerId(int maxWorkerId)
{
return new Random().Next(maxWorkerId + 1);
}
}View on GitHub (pinned to e52b8508e5)