Skip to content

Race condition - Non-atomic state updates in job processing #11

@rmcc3

Description

@rmcc3

Description

Multiple setServiceJobs calls happen in sequence within async handlers without guaranteeing order or atomicity, potentially causing state corruption.

Affected File

components/canvas-editor.tsx

Current Behavior

// First update
setServiceJobs(prev => prev.map(j => j.id === jobId ? { ...j, progress: 60 } : j))

// Later update (may race with first)
setServiceJobs(prev => prev.map(j => j.id === jobId ? { ...j, status: "Complete" } : j))

If handleServiceResult is called multiple times rapidly, updates may interleave incorrectly.

Security Impact

  • Job status may show incorrect progress
  • Completed jobs might appear as still processing
  • Could cause UI to become out of sync with actual state

Suggested Fix

Batch updates together or use a reducer pattern.

// Single atomic update with all changes
setServiceJobs(prev => prev.map(j => j.id === jobId ? { 
  ...j, 
  progress: 100, 
  status: "Complete",
  apiStatus: "COMPLETED",
  polling: false 
} : j))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions