Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix race condition in Container API #126

Draft
wants to merge 1 commit into
base: main_3x
Choose a base branch
from

Conversation

linkdd
Copy link
Collaborator

@linkdd linkdd commented May 10, 2024

Decision Record

When creating or updating a container via the API, here's what happens:

sequenceDiagram
    actor Client
    participant PluginAPI
    participant Netbox
    participant Agent

    Client ->>PluginAPI: PATCH with operation=recreate, binds=[...]
    PluginAPI->>Netbox: update Container
    Netbox->>Agent: Webhook Call
    PluginAPI->>Netbox: update binds, ...
    Agent->>Netbox: write back binds=[]
Loading

Because the creation/update is not in an atomic transaction, the Agent writes back to Netbox potentially invalid data.

To alleviate this, the Client needs to first PATCH with the data for Netbox, then PATCH operation=recreate (just as you would do in the Netbox UI).

We can skip that part if we use Django transactions.

Changes

  • 🐛 Use transaction.atomic() for container creation/update in API
  • ✅ Add test suite

@linkdd linkdd requested a review from fanshan May 10, 2024 11:10
@linkdd linkdd self-assigned this May 10, 2024
Copy link

github-actions bot commented May 10, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2177 2143 98% 90%

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: c34d54d by action🐍

@fanshan fanshan changed the base branch from main to main_3x May 27, 2024 16:07
@linkdd linkdd added the help wanted Extra attention is needed label Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant