Skip to content

Fix race condition on shared temp file in batch_predict()#83

Closed
midaa1 wants to merge 6 commits intoruxailab:mainfrom
midaa1:fix/race-condition-batch-predict
Closed

Fix race condition on shared temp file in batch_predict()#83
midaa1 wants to merge 6 commits intoruxailab:mainfrom
midaa1:fix/race-condition-batch-predict

Conversation

@midaa1
Copy link
Copy Markdown
Contributor

@midaa1 midaa1 commented Mar 2, 2026

Summary

  • Fix race condition in batch_predict() where all concurrent requests wrote to the same temp_batch_predict.csv, causing incorrect gaze predictions when multiple users hit the endpoint simultaneously
  • Generate unique temp filenames per request using uuid4 to isolate concurrent requests
  • Clean up temp files after prediction with os.remove() to prevent unbounded disk growth

Changes (app/routes/session.py)

Line Before After
9 (missing import) import uuid
165 base_path / "temp_batch_predict.csv" base_path / f"temp_batch_predict_{uuid.uuid4().hex}.csv"
190 (missing cleanup) os.remove(predict_csv_path)

Test plan

  • Send a single batch_predict request and verify correct gaze predictions are returned
  • Send two concurrent batch_predict requests with different iris_tracking_data and verify both return correct, independent results
  • Verify no temp_batch_predict_*.csv files remain in csv/data/ after requests complete

Fixes #82

midaa1 and others added 6 commits February 5, 2026 16:45
Removed push trigger for main branch and unused steps.
Added push event trigger for CI workflow and included steps for Heroku CLI installation and deployment.
Removed push trigger and Heroku deployment steps from CI workflow.
Use uuid4 to generate unique temp filenames per request, preventing
concurrent requests from overwriting each other's CSV data. Also clean
up the temp file after prediction to prevent disk space leaks.

Fixes ruxailab#82

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@midaa1 midaa1 closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race Condition: Shared temp file in batch_predict() causes incorrect gaze predictions

1 participant