Skip to content

[BUG] Stop the Elasticsearch async ForceFlush reporting success without waiting - #4337

Open
thc1006 wants to merge 14 commits into
open-telemetry:mainfrom
thc1006:fix/es-forceflush-deadline
Open

thc1006 wants to merge 14 commits into
open-telemetry:mainfrom
thc1006:fix/es-forceflush-deadline

Conversation

@thc1006

@thc1006 thc1006 commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #4336.

The old wait could return true after a condition-variable timeout because it broke before subtracting the elapsed interval. A different wake-up path could exhaust the remaining duration and return false. The old implementation also waited on the response timeout and let unrelated later completions count toward a flush.

The asynchronous Elasticsearch exporter now snapshots the pending sessions at entry and waits against a steady-clock deadline. Only sessions in that snapshot can hold this flush open. Registration moves earlier in Export so a request being prepared is counted. A nonpositive normalized timeout uses the configured response timeout. If that too is zero, the predicate is checked without a positive wait budget. The result can still be true when all required sessions have finished. The installed header changes under ENABLE_ASYNC_EXPORT: SynchronizationData replaces its counters and recursive mutex with a session id and a set of running sessions, and a test peer becomes a friend. Shutdown(timeout) still ignores its timeout, and true from ForceFlush means each snapshotted export reported an outcome, not that its batch reached Elasticsearch (#3075).

At 0aa468d the async exporter binary passed 32 cases. The synchronous build passed three and skipped 29. A separate check against the real async exporter exercised caller timeouts of zero and minus one microsecond with the response timeout at zero. Across 100 repetitions, an empty or completed snapshot returned true and a pending request returned false.

Please review #4502 first. It is the exactly-once completion work for #4338, extracted from this branch, which carries the same change. The branches currently share a merge base. When rebasing, preserve #4502's AFlushFromTheCompletionErrorDoesNotWaitForItsOwnSession case, which does not appear in this branch's test file. All 13 of #4502's selected async tests passed against this branch's production code in 20 shuffled runs. A local combined suite retained that case using this branch's flush-result assertion and passed all 33 selected async cases in 10 shuffled runs. With the session retired after the completion's error diagnostic instead of before it, that case failed in 5 of 5 runs while this branch's existing log-handler case still passed. OTLP client flush semantics are tracked separately in #4339. #4523 changes ForceFlush and Shutdown(timeout) in the same file and conflicts with this branch, so whichever lands second has to keep #4523's Shutdown(timeout).

@thc1006
thc1006 requested a review from a team as a code owner August 2, 2026 19:35
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch 4 times, most recently from c8c0e4b to bd0c772 Compare August 2, 2026 21:01
@codecov

codecov Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.00%. Comparing base (c7ad5c9) to head (5689a6f).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4337      +/-   ##
==========================================
+ Coverage   86.63%   87.00%   +0.38%     
==========================================
  Files         530      530              
  Lines       21183    21227      +44     
==========================================
+ Hits        18349    18467     +118     
+ Misses       2834     2760      -74     
Files with missing lines Coverage Δ
...y/exporters/elasticsearch/es_log_record_exporter.h 100.00% <ø> (ø)
...orters/elasticsearch/src/es_log_record_exporter.cc 96.74% <100.00%> (+49.01%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thc1006 thc1006 changed the title [BUG] Hold the Elasticsearch ForceFlush to the caller's timeout [BUG] Stop the Elasticsearch async ForceFlush reporting success without waiting Aug 3, 2026
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch 3 times, most recently from 6085fad to 703f2b0 Compare August 5, 2026 03:01
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from fac1be4 to 648de6e Compare August 11, 2026 04:11
@thc1006
thc1006 marked this pull request as draft August 13, 2026 17:45
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from 477d4ee to dbfdde9 Compare August 14, 2026 05:49
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from a572304 to 80b050f Compare August 15, 2026 08:48
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from 069dfde to 0eb3c55 Compare August 25, 2026 14:20
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from 0eb3c55 to 52470cf Compare August 31, 2026 09:50
@thc1006

thc1006 commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

The one red is Bazel asan config, and it is not from this diff. BasicCurlHttpTests.ElegantQuitQuick in //ext/test/http:curl_http_test missed its 20 ms wall clock budget at curl_http_test.cc:940. That is the flake #4342 described and #4488 fixes; #4342 is closed, the flake is not.

This branch changes five files, all under exporters/elasticsearch/, so rather than argue it from the diff:

$ bazel query "somepath(//ext/test/http:curl_http_test, //exporters/elasticsearch/...)"
INFO: Empty results

The same job is green on main at 70fdb766, the commit this is rebased onto.

I cannot re-run a job here, so it will clear on the next push or on a maintainer re-run.

thc1006 added a commit to thc1006/opentelemetry-cpp that referenced this pull request Aug 31, 2026
AsyncResponseHandler called the result callback directly from OnResponse and from
each terminal OnEvent state with no guard, and ReadError, WriteError and Destroyed
fell through a default label and called nothing. The HTTP client can deliver both
a response and a terminal event for one request, so one export could report twice,
and it can end on one of those three states and report nothing at all.

The exporter counts one finished session per export. Reporting twice overshoots
that count for the life of the exporter. Reporting never leaves a flush waiting on
a session that has already ended.

Every path goes through one CompleteOnce now, a compare exchange that reports at
most once and keeps the first verdict. The switch lists every state with no
default, so a state added upstream fails to compile rather than going uncounted,
and the destructor reports a failure for a handler torn down without an outcome.

The completion line said trace span(s) in the log exporter and says log record(s)
now. The cases read that line to count outcomes, and the wording was wrong either
way.

Nine cases drive a fake HTTP client through the public constructor: each terminal
ordering a real session can produce, a response and a teardown event in both
orders, and the concurrent version of each. Removing the compare exchange turns
six of the nine red.

Extracted from open-telemetry#4337, which is 1526 lines and closes two issues. What stays there
is the ForceFlush deadline and watermark accounting for open-telemetry#4336, including four
completion cases that verify this guard through the flush rather than through the
log line.

Signed-off-by: thc1006 <[email protected]>
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from 52470cf to b3a560f Compare September 1, 2026 12:02
thc1006 added a commit to thc1006/opentelemetry-cpp that referenced this pull request Sep 1, 2026
AsyncResponseHandler called the result callback directly from OnResponse and from
each terminal OnEvent state with no guard, and ReadError, WriteError and Destroyed
fell through a default label and called nothing. The HTTP client can deliver both
a response and a terminal event for one request, so one export could report twice,
and it can end on one of those three states and report nothing at all.

The exporter counts one finished session per export. Reporting twice overshoots
that count for the life of the exporter. Reporting never leaves a flush waiting on
a session that has already ended.

Every path goes through one CompleteOnce now, a compare exchange that reports at
most once and keeps the first verdict. The switch lists every state with no
default, so a state added upstream fails to compile rather than going uncounted,
and the destructor reports a failure for a handler torn down without an outcome.

The completion line said trace span(s) in the log exporter and says log record(s)
now. The cases read that line to count outcomes, and the wording was wrong either
way.

Nine cases drive a fake HTTP client through the public constructor: each terminal
ordering a real session can produce, a response and a teardown event in both
orders, and the concurrent version of each. Removing the compare exchange turns
six of the nine red.

Extracted from open-telemetry#4337, which is 1526 lines and closes two issues. What stays there
is the ForceFlush deadline and watermark accounting for open-telemetry#4336, including four
completion cases that verify this guard through the flush rather than through the
log line.

Signed-off-by: thc1006 <[email protected]>
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from b3a560f to dfb0c34 Compare September 1, 2026 12:14
thc1006 added a commit to thc1006/opentelemetry-cpp that referenced this pull request Sep 1, 2026
AsyncResponseHandler called the result callback directly from OnResponse and from
each terminal OnEvent state with no guard, and ReadError, WriteError and Destroyed
fell through a default label and called nothing. The HTTP client can deliver both
a response and a terminal event for one request, so one export could report twice,
and it can end on one of those three states and report nothing at all.

The exporter counts one finished session per export. Reporting twice overshoots
that count for the life of the exporter. Reporting never leaves a flush waiting on
a session that has already ended.

Every path goes through one CompleteOnce now, a compare exchange that reports at
most once and keeps the first verdict. The switch lists every state with no
default, so a state added upstream fails to compile rather than going uncounted,
and the destructor reports a failure for a handler torn down without an outcome.

The completion line said trace span(s) in the log exporter and says log record(s)
now. The cases read that line to count outcomes, and the wording was wrong either
way.

Nine cases drive a fake HTTP client through the public constructor: each terminal
ordering a real session can produce, a response and a teardown event in both
orders, and the concurrent version of each. Removing the compare exchange turns
six of the nine red.

Extracted from open-telemetry#4337, which is 1526 lines and closes two issues. What stays there
is the ForceFlush deadline and watermark accounting for open-telemetry#4336, including four
completion cases that verify this guard through the flush rather than through the
log line.

Signed-off-by: thc1006 <[email protected]>
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from dfb0c34 to c4033ed Compare September 1, 2026 13:14
AsyncResponseHandler called the result callback directly from OnResponse and from
each terminal OnEvent state with no guard, and ReadError, WriteError and Destroyed
fell through a default label and called nothing. The HTTP client can deliver both
a response and a terminal event for one request, so one export could report twice,
and it can end on one of those three states and report nothing at all.

The exporter counts one finished session per export. Reporting twice overshoots
that count for the life of the exporter. Reporting never leaves a flush waiting on
a session that has already ended.

Every path goes through one CompleteOnce now, a compare exchange that reports at
most once and keeps the first verdict. The switch lists every state with no
default, so a state added upstream fails to compile rather than going uncounted,
and the destructor reports a failure for a handler torn down without an outcome.

The completion line said trace span(s) in the log exporter and says log record(s)
now. The cases read that line to count outcomes, and the wording was wrong either
way.

Nine cases drive a fake HTTP client through the public constructor: each terminal
ordering a real session can produce, a response and a teardown event in both
orders, and the concurrent version of each. Removing the compare exchange turns
six of the nine red.

Extracted from open-telemetry#4337, which is 1526 lines and closes two issues. What stays there
is the ForceFlush deadline and watermark accounting for open-telemetry#4336, including four
completion cases that verify this guard through the flush rather than through the
log line.

Signed-off-by: thc1006 <[email protected]>
Main's open-telemetry#4071 and open-telemetry#4501 put FakeResponse, FakeRequest, FakeSession and
FakeHttpClient in an unnamed namespace at the top of this file, and this
branch already had four of those names in a second unnamed namespace lower
down. Reopening an unnamed namespace names the same namespace, so the
rebase merged both with no conflict at all and left four redefinitions.

One set now. The session and the client take a script and default to
answering the way main's did, so main's own call site needs no edit. The
script carries the handler as a shared_ptr rather than a reference, because
the cases here have to keep it and send a second event to it, and the
client keeps its on_create_session and on_cancel_all hooks, both empty by
default.

The default body stays as main wrote it. This branch does not change how
the exporter decides success, so what main's cases send still passes here.

Verified in both configurations with maintainer mode on: 12 cases, 12
passing with async export and 3 passing with 9 skipping without it.
Removing CompleteOnce's compare and exchange turns six of them red, so the
rewritten fixtures still discriminate.

Signed-off-by: thc1006 <[email protected]>
…on identity

ForceFlush waited for options_.response_timeout_ rather than the caller's
timeout, and the timeout branch returned true whatever had happened, so every
flush that ran out of time reported success. It also compared monotonic totals
with no session identity, so a completion from a session started after the call
could satisfy a waiter for one started before it, and a batch already inside
Export() was not waited for at all.

One steady_clock deadline taken at entry, and a wait on a predicate over the set
of running session ids against a watermark. wait_until returns the predicate, so
the answer is the caller's question rather than a leftover duration. The
serialising lock is gone: each call snapshots what it waits for and publishes
nothing, so two callers were already safe side by side.

Stacked on open-telemetry#4502, which carries the exactly-once completion this accounting
depends on. That half was extracted so each pull request closes one issue and is
reviewable on its own.

Signed-off-by: thc1006 <[email protected]>
@thc1006
thc1006 force-pushed the fix/es-forceflush-deadline branch from c4033ed to 0109b5c Compare September 8, 2026 06:50
thc1006 added a commit to thc1006/opentelemetry-cpp that referenced this pull request Sep 21, 2026
AsyncResponseHandler called the result callback directly from OnResponse and from
each terminal OnEvent state with no guard, and ReadError, WriteError and Destroyed
fell through a default label and called nothing. The HTTP client can deliver both
a response and a terminal event for one request, so one export could report twice,
and it can end on one of those three states and report nothing at all.

The exporter counts one finished session per export. Reporting twice overshoots
that count for the life of the exporter. Reporting never leaves a flush waiting on
a session that has already ended.

Every path goes through one CompleteOnce now, a compare exchange that reports at
most once and keeps the first verdict. The switch lists every state with no
default, so a state added upstream fails to compile rather than going uncounted,
and the destructor reports a failure for a handler torn down without an outcome.

The completion line said trace span(s) in the log exporter and says log record(s)
now. The cases read that line to count outcomes, and the wording was wrong either
way.

Nine cases drive a fake HTTP client through the public constructor: each terminal
ordering a real session can produce, a response and a teardown event in both
orders, and the concurrent version of each. Removing the compare exchange turns
six of the nine red.

Extracted from open-telemetry#4337, which is 1526 lines and closes two issues. What stays there
is the ForceFlush deadline and watermark accounting for open-telemetry#4336, including four
completion cases that verify this guard through the flush rather than through the
log line.

Signed-off-by: thc1006 <[email protected]>
Signed-off-by: thc1006 <[email protected]>

# Conflicts:
#	CHANGELOG.md
Signed-off-by: thc1006 <[email protected]>

# Conflicts:
#	CHANGELOG.md
Signed-off-by: thc1006 <[email protected]>

# Conflicts:
#	CHANGELOG.md
The ForceFlush contract is now ten lines, which is the longest doxygen block
main carries in this header. Three others led with an abstraction and then
explained it; they now name the function or the flag and stop.

es_log_record_exporter_test passes 32 of 32 in the async build and clang-format
18.1.8 is clean on all three files.

Signed-off-by: thc1006 <[email protected]>
Signed-off-by: thc1006 <[email protected]>

# Conflicts:
#	CHANGELOG.md
Git merged the changelog without a conflict and still put the entry inside
the 1.30.0 section, where it reads as already released. Rebuilt as main's
changelog with this branch's two entries under Unreleased, so the only
difference from main is those entries.

Signed-off-by: thc1006 <[email protected]>
The Unreleased section is the only conflict. Rebuilt as main's changelog
with this branch's entries under Unreleased.

Signed-off-by: thc1006 <[email protected]>
@thc1006
thc1006 marked this pull request as ready for review November 4, 2026 07:16
…tions

They are compiled with and without async export and skip in synchronous
builds. The section comment said they were built only with async export.

Signed-off-by: thc1006 <[email protected]>
The default timeout is max, which the call turns into zero and then into
the response timeout. The comment said the wait was bounded by the
caller's timeout rather than the response timeout, which is only true
for a positive timeout below max.

Signed-off-by: thc1006 <[email protected]>

This branch has not been deployed

No deployments
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.

[BUG] Elasticsearch async ForceFlush reports success on timeout and ignores the caller deadline

1 participant