Fix race condition in _set_timeline_status on new imports#3864
Merged
Conversation
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
Collaborator
Author
|
/gemini review |
Contributor
There was a problem hiding this comment.
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Alexander J <741037+jaegeral@users.noreply.github.com>
jkppr
marked this pull request as ready for review
June 26, 2026 13:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_statusunconditionally 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 guaranteedNotFoundError(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_statuswith 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
pytest timesketch/lib/inside the dev container (302 passed, 108 skipped).import_plaso_filter_testandstatus_race_test).