Skip to content

fix: avoid race in IngestionSmokeTest.test_streamLogs_ofCancelledTask - #20549

Open
rishi-rana wants to merge 3 commits into
apache:masterfrom
rishi-rana:fix-flaky-cancelled-task-log-stream
Open

rishi-rana wants to merge 3 commits into
apache:masterfrom
rishi-rana:fix-flaky-cancelled-task-log-stream

Conversation

@rishi-rana

Copy link
Copy Markdown

Fixes #20435.

Description

test_streamLogs_ofCancelledTask polls TaskLogStreamer#streamTaskLog with waitForResult(..., Optional::isPresent). In the Docker-based embedded test setup, the peon pushes its log after the process exits, so the stream can become present (e.g. an empty file/handle) before the expected content has actually been written. This makes the test's assertFalse(logs.isEmpty()) fail intermittently.

This PR moves the log read into the polling supplier itself and changes the match condition to wait until the log content contains the expected line (Running task[%s] for [%d] millis), rather than just waiting for the stream to be present.

Fixed the race in test_streamLogs_ofCancelledTask

Polls on log content instead of stream presence, so the test waits out the delayed log push instead of racing it.

Release note

N/A — test-only change, no user-facing impact.


Key changed/added classes in this PR
  • IngestionSmokeTest

This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.

Assisted with AI Claude.

The peon pushes its task log after the process exits, so
TaskLogStreamer#streamTaskLog can return a present-but-empty stream before
the expected content is written. Poll until the log contains the expected
line instead of just until the stream is present.

Fixes apache#20435.

Assisted with AI Claude.
@ykisana

ykisana commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Left a comment here: #20435 (comment)

I'll investigate that more.

taskId, runDurationMillis
);

// The peon pushes its log after the process exits, so the stream can become present before it

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.

This comment isn't accurate, no peon in this setup.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, thanks — you're right, there's no peon here. EmbeddedIndexer runs the task in-process and the log is served over HTTP straight from its own process log file (HttpRemoteTaskRunner#streamTaskLog). Updated the comment to describe that instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry that was a oversight on my side

@ykisana pointed out this test's setup has no peon — EmbeddedIndexer runs
tasks in-process and the log is served over HTTP from its own process log
file (HttpRemoteTaskRunner#streamTaskLog). Fix the comment to describe that
mechanism instead of a peon process-exit push.

Assisted with AI Claude.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟡 Changes recommended

The retry fixes the log-visibility race, but each retry opens a new task-log stream without closing it. File-backed streams can leak descriptors across retries and make embedded test runs flaky.

Reviewed 1 of 1 changed files; finding in 1 file.

Validation: git diff --check passed.

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

This is an automated review by Codex GPT-5.6-Luna(max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

Each retry of the waitForResult poll opened a new InputStream from
streamTaskLog without closing it. Close it with try-with-resources after
reading, so retries don't leak file/HTTP response descriptors.

Assisted with AI Claude.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟢 Approval recommended

No actionable issues found in this review. The current head closes each present task-log InputStream after every polling read, so retries no longer accumulate file or HTTP response descriptors while preserving the wait-until-content behavior.

Reviewed 1 of 1 changed files, including the full diff, the incremental follow-up change, the embedded test setup, the retry waiter, and the task-log streaming implementations and call sites.

Validation: git diff --check FETCH_HEAD HEAD passed.


This is an automated review by Codex GPT-5.6 Luna(Max)

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.

Flaky test: IngestionSmokeTest.test_streamLogs_ofCancelledTask (ConsulDiscoveryPlainDockerTest)

3 participants