Skip to content

Fix race condition in _set_timeline_status on new imports#3864

Merged
jkppr merged 5 commits into
google:masterfrom
jkppr:fix-import-race-condition
Jun 29, 2026
Merged

Fix race condition in _set_timeline_status on new imports#3864
jkppr merged 5 commits into
google:masterfrom
jkppr:fix-import-race-condition

Conversation

@jkppr

@jkppr jkppr commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

This PR addresses a race condition that occurs during new timeline imports (specifically CSV/JSONL imports).

Problem:
When a new import is initiated, the task updates the datasource status to "processing", which in turn calls _set_timeline_status. Previously, _set_timeline_status unconditionally attempted to refresh the corresponding OpenSearch index. However, for CSV/JSONL imports, the index is created after this "processing" status is set. This resulted in a guaranteed NotFoundError (404) and a 4-second delay due to the retry loop (5 attempts with 1-second sleep) before the import could proceed.

Solution:
Wrapped the index refresh logic in _set_timeline_status with a check to only execute when the status is "ready". The index is now only refreshed when the timeline is fully populated and ready for analysis, avoiding unnecessary errors and delays during the initial processing phase.

Testing

  • Unit Tests: Ran pytest timesketch/lib/ inside the dev container (302 passed, 108 skipped).
  • End-to-End Tests: Ran the full E2E test suite inside the container (80/80 tests passed, including import_plaso_filter_test and status_race_test).

Only refresh the OpenSearch index when the timeline status is set to "ready".
Previously, the index was refreshed unconditionally, including when the status
was set to "processing" during CSV/JSONL import initiation. Since the index is
created after the "processing" status is set, this caused a guaranteed 4-second
delay (due to retries) and logged NotFoundError exceptions.

BUG=503439192
TAG=agy
CONV=6c802e06-0d55-421c-b9b0-f1a6a9cfb07b
@jkppr jkppr self-assigned this Jun 24, 2026
@jkppr

jkppr commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates timesketch/lib/tasks.py to conditionally refresh the OpenSearch index only when the timeline status is "ready". The review feedback highlights two key improvements: adding a defensive check to prevent a potential AttributeError if timeline.searchindex is None, and correcting a minor spacing typo in a debug log message.

Comment thread timesketch/lib/tasks.py
Comment thread timesketch/lib/tasks.py
jaegeral and others added 2 commits June 26, 2026 09:56
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@jaegeral jaegeral left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

Comment thread timesketch/lib/tasks.py
Co-authored-by: Alexander J <741037+jaegeral@users.noreply.github.com>
@jkppr
jkppr marked this pull request as ready for review June 26, 2026 13:59
@jkppr
jkppr merged commit 76f75c7 into google:master Jun 29, 2026
14 checks passed
@jkppr
jkppr deleted the fix-import-race-condition branch June 29, 2026 07:33
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.

2 participants