towerops/lib
Graham McIntire 2b4cb5c3f5
fix: handle duplicate MAC address entries gracefully
Problem: upsert_mac_address was using Repo.one() which crashes with
Ecto.MultipleResultsError when duplicate MAC address records exist
in the database.

Root Cause: Race condition or historical data corruption created
duplicate entries for the same (device_id, mac_address, vlan_id)
tuple, violating the unique constraint.

Fix:
- Changed Repo.one() to Repo.all() to handle duplicates gracefully
- When duplicates found: keep first entry, delete extras, log warning
- Includes device_id, mac_address, vlan_id, and duplicate IDs in log
- Auto-cleans corrupted data while maintaining service availability

Example Log Output:
  Found 1 duplicate MAC address entries, cleaning up
  device_id=f3ff19d5-b519-4327-9f7d-dc416e494cfa
  mac_address=78:9a:18:52:b1:c6
  vlan_id=nil
  duplicate_ids=[...]

Impact:
- Prevents polling crashes when duplicate MAC entries exist
- Self-healing: automatically cleans up database corruption
- Maintains data integrity while preserving service availability

Related: Issue 2.9 from bugs analysis (ARP/MAC parsing issues)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-09 09:20:08 -06:00
..
mix/tasks Remove debugging logs, fix Mix.env call 2026-02-04 12:10:48 -06:00
snmpkit security: fix critical vulnerabilities and atom exhaustion risks 2026-02-08 10:30:30 -06:00
towerops fix: handle duplicate MAC address entries gracefully 2026-02-09 09:20:08 -06:00
towerops_web fix: resolve critical data loss and protobuf schema bugs (Phase 1) 2026-02-09 09:16:03 -06:00
snmp_lib.ex bring in snmpkit 2026-01-23 12:52:17 -06:00
snmp_mgr.ex credo fixes 2026-01-23 14:01:52 -06:00
snmpkit.ex complete overhaul of snmp engine 2026-01-30 10:41:07 -06:00
towerops.ex init 2025-12-21 11:10:43 -06:00
towerops_native.ex complete overhaul of snmp engine to C nif 2026-01-30 12:27:12 -06:00
towerops_web.ex feat: implement gettext infrastructure (Phase 1) 2026-02-02 09:40:32 -06:00