Conversation
fc104af to
779767c
Compare
…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 <84045975+thc1006@users.noreply.github.com>
779767c to
e2d4113
Compare
…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 <84045975+thc1006@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4502 +/- ##
==========================================
+ Coverage 86.52% 86.78% +0.27%
==========================================
Files 525 525
Lines 20475 20488 +13
==========================================
+ Hits 17713 17778 +65
+ Misses 2762 2710 -52
🚀 New features to boost your workflow:
|
e2d4113 to
f9817df
Compare
…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 <84045975+thc1006@users.noreply.github.com>
f9817df to
9d5224c
Compare
…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 <84045975+thc1006@users.noreply.github.com>
There was a problem hiding this comment.
Reviewed this against the sync-path counterpart of this exact accounting (the finished_session_counter_/force_flush_cv machinery in #4523's ForceFlush fix). The CompleteOnce() compare-exchange is the right shape: it closes both the double-report case (response + terminal event both firing) and the destructor gap (a handler torn down with no outcome at all previously left a flush waiting on a session that would never finish). Confirmed the switch is genuinely exhaustive against all 15 SessionState values, and the concurrency tests (ConcurrentTerminalEventsReportOnce, AConcurrentResponseAndTerminalEventReportOnce) actually exercise the race the atomic exists for, not just the sequential orderings.
One thing I want to flag: the comment on AFlushFromTheShutdownErrorDoesNotWaitForItsOwnExport says "The export is registered before the shutdown check, so reporting the refusal before retiring it makes a flushing handler wait for the Export() that is calling it." That doesn't match what actually happens on this path: session_counter_.fetch_add() in Export() only runs after the isShutdown() check passes, so a refused export is never registered at all. The reason the re-entrant ForceFlush() call here doesn't hang isn't retirement ordering, it's that (a) nothing was ever counted for this export, and (b) force_flush_m is a std::recursive_mutex, so the same thread re-entering it from inside the log call it's already holding succeeds instead of deadlocking. The test itself pins real, correct behavior, but the comment explaining why it passes looks copied from the response/session-retirement reasoning above it rather than describing this specific path. Worth a one-line fix so a future reader isn't misled about which mechanism is doing the work here.
Nothing else stood out as incorrect.
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 <84045975+thc1006@users.noreply.github.com>
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 <84045975+thc1006@users.noreply.github.com>
Both asserted EXPECT_TRUE(flushed()), and ForceFlush() reports success when it gives up on its own condition variable, so the return value cannot tell a flush that had nothing to wait for from one that waited the whole response timeout. Inverting either ordering left both cases green at 2000 ms, the timeout they exist to rule out. Time the re-entrant flush and bound it instead. Also correct the comment on AFlushFromTheShutdownErrorDoesNotWaitForItsOwnExport. It said the export is registered before the shutdown check; the check returns first, so nothing is registered for a refused export, which is what makes the re-entrant flush return immediately on that path. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
9d5224c to
e2fda01
Compare
|
You are right, and chasing it found something worse than the comment. On the comment: On your (b): Then I tried to prove that with a mutation, and the test did not fail. Registering the export before the shutdown check, which is exactly the hang the case is named for, left it green. It went from 0 ms to 2000 ms, the
So the handler now times the re-entrant flush and both cases bound it at half the response timeout. Measured on the same tree:
Unmutated, 12 of 12 pass in the async build and 3 pass with 9 skipped in the sync one, both with maintainer mode and no warnings. The branch is also rebased onto Thanks for reading it closely enough that the wrong sentence was worth chasing. That |
OnResponse() reports through CompleteOnce() before it logs, so a log handler that calls ForceFlush() does not wait for the session reporting to it. The callback CompleteOnce() invokes does the opposite: it writes its own diagnostic first and counts the session finished afterwards, so a handler watching that line waits the whole response timeout. Measured at 2000158us. Count and wake first, then log, and cover that message with a case of its own. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
|
One more, from carrying your point further: the same rule was broken on a third path, and none of the cases were watching it.
if (result != kSuccess) { OTEL_INTERNAL_LOG_ERROR("... ERROR: Export ..."); }
...
synchronization_data->finished_session_counter_.fetch_add(1, ...);
synchronization_data->force_flush_cv.notify_all();So a handler watching Counted and woken first now, then logged, with a case for that message. Inverted, it fails at 2000158us; as it stands, 13 of 13 pass in the async build and 3 pass with 10 skipped in the sync one, both maintainer mode, no warnings. That line is on For the record on the other point: |
AHandlerDestroyedWithoutAnOutcomeStillFinishes asserted EXPECT_TRUE(ForceFlush(...)) like the other two did, so removing the completion from ~AsyncResponseHandler left it green at 2000 ms. It now times the flush through the same helper the re-entrant cases use. The comments the change adds are cut to describe the code rather than explain it, none longer than what it annotates. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
|
Third one, and it was the case you singled out.
Every ordering in this pull request is pinned by a mutation that has to fail:
Unmutated: 13 of 13 pass in the async build, 3 pass with 10 skipped in the sync one, both maintainer mode with no warnings, and Bazel TSan runs the 13 with no data race. Two other things while I was in here. The comments are cut back to describe the code rather than argue for it, none longer than what it annotates. The longest block that remains is the The two log lines the callback change moves also said |
kFlushDidNotWaitUs came from options_.response_timeout_, which is only what a waiting flush burns because ForceFlush ignores the caller deadline (open-telemetry#4336). A fix there would have left a broken ordering waiting 20ms, under the bound, and every one of these cases would have stopped failing without saying so. Ask for 200ms and bound at half of it, so the two outcomes stay apart either way. Checked by applying a caller-deadline fix and re-running the mutation: it fails at 200110us instead of 2000434us. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
|
One more, and it was the bound itself.
So the case now asks for 200ms and bounds at half of it, which separates the two outcomes whether or not the deadline is honoured. Checked by applying a caller-deadline fix to
All four orderings still fail when inverted on the branch as it stands: 2000120us, 2000121us, 2000108us, 2000108us. Unmutated, 13 of 13 in the async build, 3 with 10 skipped in the sync one, no warnings, and Bazel TSan runs the 13 with no data race. On issues, since this touches two that are already open rather than needing new ones:
I could not find a third thing worth filing. The remaining items I ran into are covered by #4359 for |
Retiring the session before the completion callback logs changes what a caller sees: a log handler that calls ForceFlush() from that line used to wait for the export reporting to it, measured at 2000276us. That is a behaviour change and belongs in the entry rather than only in the pull request body. The completion line also says log record(s) rather than trace span(s) now, which is observable output. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
…lemetry#4502 Applied thc1006's patch from PR review: HoldingSession now parks the handler in a variable the test case owns instead of dropping it, so an export through it stays outstanding regardless of what open-telemetry#4502 changes about AsyncResponseHandler's destructor. A raw pointer to the parked variable (not a shared_ptr) keeps the session/client from forming a reference cycle with the handler.
Fixes #4338.
AsyncResponseHandlercalls the exporter's result callback directly fromOnResponseand from each terminalOnEventstate with no guard, andReadError,WriteErrorandDestroyedfall through adefaultlabel and call nothing.The HTTP client can deliver both a response and a terminal event for one request, so one export can report twice. It can also end on one of those three states and report nothing at all. The exporter counts one finished session per export, so the first overshoots that count for the life of the exporter, and the second leaves a flush waiting on a session that has already ended.
Every path goes through one
CompleteOncenow, a compare exchange that reports at most once and keeps the first verdict. The switch lists every state with nodefault, 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.Every path that reports also retires the session before it writes anything a user can replace.
OnResponse()already did; the callbackCompleteOnce()invokes did not, and logged its own line first, so a handler that calledForceFlush()from that line waited for the session reporting to it. Measured at 2000276us before the reorder.One thing comes with it that is not strictly the fix. The completion line said
trace span(s)in the log exporter; it sayslog record(s)now. The cases below read that line to count outcomes, and the wording was wrong either way.Thirteen cases run in the async build in
es_log_record_exporter_test.cc, driven by 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, the concurrent version of each, and four that time a re-entrant flush. Removing the compare exchange turns six of the thirteen red. The sync build runs three and skips ten.Extracted from #4337, which is +1399 and closes two issues. What stays there is the
ForceFlushdeadline and watermark accounting for #4336, including four completion cases that verify this guard through the flush rather than through the log line, which need that accounting to work.Two open issues this sits next to
#4435, a log handler that calls
ForceFlush()re-entrantly. Not closed here. The two shapes that issue describes, flushing from a callback the client dispatches and flushing before the request has been handed over, are untouched. What is closed is the narrower half it names, an export's own terminal diagnostic: every path that reports now retires the session before it logs, and four cases hold that by timing the re-entrant flush.#4336,
ForceFlush()reporting success on its own timeout and ignoring the caller deadline. Also untouched. It matters here only because those four cases must not depend on it: the bound comes from the timeout they ask for rather than fromresponse_timeout_, so a fix there leaves them failing on a broken ordering instead of quietly passing.For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes