Race condition allows creating duplicate IP addresses #6947

Closed
opened 2025-12-29 19:47:04 +01:00 by adam · 1 comment
Owner

Originally created by @fabi125 on GitHub (Sep 7, 2022).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.3.2

Python version

3.8

Steps to Reproduce

  1. Create a VRF that enforces unique addresses, e.g. https://demo.netbox.dev/ipam/vrfs/6/
  2. Send two parallel API requests to Netbox, both trying to create the same IP:
$ curl -X POST -H "Authorization: Token <token>" -H "Content-Type: application/json" https://demo.netbox.dev/api/ipam/ip-addresses/ -d '{"address": "192.168.2.1/24", "vrf": 
6}' & curl -X POST -H "Authorization: Token <token>" -H "Content-Type: application/json" https://demo.netbox.dev/api/ipam/ip-addresses/ -d '{"address": "192.168.2.1/24", "vrf": 6}' &

Expected Behavior

One request should create the IP, the other should fail.

Observed Behavior

Both requests create new objects. curl responses:

{"id":191,"url":"https://demo.netbox.dev/api/ipam/ip-addresses/191/","display":"192.168.2.1/24","family":{"value":4,"label":"IPv4"},"address":"192.168.2.1/24","vrf":{"id":6,"url":"https://demo.netbox.dev/api/ipam/vrfs/6/","display":"Shared (65000:1)","name":"Shared","rd":"65000:1"},"tenant":null,"status":{"value":"active","label":"Active"},"role":null,"assigned_object_type":null,"assigned_object_id":null,"assigned_object":null,"nat_inside":null,"nat_outside":[],"dns_name":"","description":"","tags":[],"custom_fields":{},"created":"2022-09-07T15:39:56.361057Z","last_updated":"2022-09-07T15:39:56.361078Z"}

and

{"id":192,"url":"https://demo.netbox.dev/api/ipam/ip-addresses/192/","display":"192.168.2.1/24","family":{"value":4,"label":"IPv4"},"address":"192.168.2.1/24","vrf":{"id":6,"url":"https://demo.netbox.dev/api/ipam/vrfs/6/","display":"Shared (65000:1)","name":"Shared","rd":"65000:1"},"tenant":null,"status":{"value":"active","label":"Active"},"role":null,"assigned_object_type":null,"assigned_object_id":null,"assigned_object":null,"nat_inside":null,"nat_outside":[],"dns_name":"","description":"","tags":[],"custom_fields":{},"created":"2022-09-07T15:39:56.365484Z","last_updated":"2022-09-07T15:39:56.365503Z"}

Trying to create the same again results as expected in an error:

{"address":["Duplicate IP address found in VRF Shared (65000:1): 192.168.2.1/24"]}
Originally created by @fabi125 on GitHub (Sep 7, 2022). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.3.2 ### Python version 3.8 ### Steps to Reproduce 1. Create a VRF that enforces unique addresses, e.g. https://demo.netbox.dev/ipam/vrfs/6/ 2. Send two parallel API requests to Netbox, both trying to create the same IP: ``` $ curl -X POST -H "Authorization: Token <token>" -H "Content-Type: application/json" https://demo.netbox.dev/api/ipam/ip-addresses/ -d '{"address": "192.168.2.1/24", "vrf": 6}' & curl -X POST -H "Authorization: Token <token>" -H "Content-Type: application/json" https://demo.netbox.dev/api/ipam/ip-addresses/ -d '{"address": "192.168.2.1/24", "vrf": 6}' & ``` ### Expected Behavior One request should create the IP, the other should fail. ### Observed Behavior Both requests create new objects. curl responses: ``` {"id":191,"url":"https://demo.netbox.dev/api/ipam/ip-addresses/191/","display":"192.168.2.1/24","family":{"value":4,"label":"IPv4"},"address":"192.168.2.1/24","vrf":{"id":6,"url":"https://demo.netbox.dev/api/ipam/vrfs/6/","display":"Shared (65000:1)","name":"Shared","rd":"65000:1"},"tenant":null,"status":{"value":"active","label":"Active"},"role":null,"assigned_object_type":null,"assigned_object_id":null,"assigned_object":null,"nat_inside":null,"nat_outside":[],"dns_name":"","description":"","tags":[],"custom_fields":{},"created":"2022-09-07T15:39:56.361057Z","last_updated":"2022-09-07T15:39:56.361078Z"} ``` and ``` {"id":192,"url":"https://demo.netbox.dev/api/ipam/ip-addresses/192/","display":"192.168.2.1/24","family":{"value":4,"label":"IPv4"},"address":"192.168.2.1/24","vrf":{"id":6,"url":"https://demo.netbox.dev/api/ipam/vrfs/6/","display":"Shared (65000:1)","name":"Shared","rd":"65000:1"},"tenant":null,"status":{"value":"active","label":"Active"},"role":null,"assigned_object_type":null,"assigned_object_id":null,"assigned_object":null,"nat_inside":null,"nat_outside":[],"dns_name":"","description":"","tags":[],"custom_fields":{},"created":"2022-09-07T15:39:56.365484Z","last_updated":"2022-09-07T15:39:56.365503Z"} ``` Trying to create the same again results as expected in an error: ``` {"address":["Duplicate IP address found in VRF Shared (65000:1): 192.168.2.1/24"]} ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:47:05 +01:00
adam closed this issue 2025-12-29 19:47:05 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 9, 2022):

We employ advisory database locks to avoid creating duplicate IPs via the available-ips REST API endpoint. Maybe a similar approach can be used here.

@jeremystretch commented on GitHub (Sep 9, 2022): We employ advisory database locks to avoid creating duplicate IPs via the `available-ips` REST API endpoint. Maybe a similar approach can be used here.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6947