[PR #3726] [MERGED] Fix race condition in available-prefix/ip APIs #12621

Closed
opened 2025-12-29 22:22:42 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/3726
Author: @mattolenik
Created: 12/5/2019
Status: Merged
Merged: 2/14/2020
Merged by: @jeremystretch

Base: developHead: fix-2519


📝 Commits (1)

  • 2e83ce7 Fix race condition in available-prefix/ip APIs

📊 Changes

4 files changed (+26 additions, -0 deletions)

View changed files

📝 base_requirements.txt (+4 -0)
📝 netbox/ipam/api/views.py (+10 -0)
📝 netbox/utilities/constants.py (+11 -0)
📝 requirements.txt (+1 -0)

📄 Description

Fixes: #2519

Use an advisory lock to create mutual exclusion and prevent these APIs from being called in parallel. If the API is called in one session, other sessions will have to wait for the first to finish. This prevents simultaneous calls that trample each other and insert duplicate records, which would result in multiple callers receiving the same prefix/IP.

Tests work by making many parallel calls and ensuring that only the expected number of records are actually created.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/3726 **Author:** [@mattolenik](https://github.com/mattolenik) **Created:** 12/5/2019 **Status:** ✅ Merged **Merged:** 2/14/2020 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `fix-2519` --- ### 📝 Commits (1) - [`2e83ce7`](https://github.com/netbox-community/netbox/commit/2e83ce76eddc7f5d7cfb38430c70efc352b0b10e) Fix race condition in available-prefix/ip APIs ### 📊 Changes **4 files changed** (+26 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `base_requirements.txt` (+4 -0) 📝 `netbox/ipam/api/views.py` (+10 -0) 📝 `netbox/utilities/constants.py` (+11 -0) 📝 `requirements.txt` (+1 -0) </details> ### 📄 Description ### Fixes: #2519 Use an [advisory lock](https://www.postgresql.org/docs/9.4/explicit-locking.html#ADVISORY-LOCKS) to create mutual exclusion and prevent these APIs from being called in parallel. If the API is called in one session, other sessions will have to wait for the first to finish. This prevents simultaneous calls that trample each other and insert duplicate records, which would result in multiple callers receiving the same prefix/IP. Tests work by making many parallel calls and ensuring that only the expected number of records are actually created. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:22:42 +01:00
adam closed this issue 2025-12-29 22:22:42 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12621