Skip to content

Fix: Race Condition in Connection Accept #44

Description

@Techhackontime999

Description

When two users simultaneously accept each other's connection requests, duplicate connections are created in the database.

Steps to Reproduce

  1. User A sends connection request to User B
  2. User B sends connection request to User A
  3. Both users click "Accept" at nearly the same time
  4. Two connection records are created instead of one

Expected Behavior

Only one connection record should exist regardless of timing. Use database-level locking or atomic operations to prevent duplicates.

Root Cause

The �ccept_request view doesn't check for an existing accepted connection before creating a new one, and there's no database constraint or lock preventing race conditions.

Files to Fix

  • linkup/network/views.py - Add select_for_update() in accept view, check for existing accepted connection
  • linkup/network/models.py - Add unique constraint on (user, friend) pairs
  • Run python manage.py makemigrations and migrate

Acceptance Criteria

  • No duplicate connections can be created
  • Atomic operation prevents race condition
  • Both users see each other as connected
  • Database constraint enforced at schema level

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    advancedAdvanced levelbackendBackend/API workbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions