You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6d71cc5
Browse filesBrowse the repository at this point in the historyBrowse files
[EXPORTER] OTLP ForceFlush waits for the requests it was called with
ForceFlush on both OTLP clients compared two lifetime totals, started and
finished, so it waited for a number of completions rather than for the requests
it was called with. A request that starts after the call and finishes before a
pending one supplies one of those completions, and the flush then reported
success with the earlier request still in flight. owent stated the contract on
issue 4339: ForceFlush(timeout) returns true only when all requests that were
pending before the call have completed.
Both clients already register every request, OtlpHttpClient in running_sessions_
and OtlpGrpcClient in async_data->running_calls, so only an order was missing.
Each entry carries a sequence taken from the existing monotonic start counter,
and the flush asks whether any entry still has a sequence below the one it was
entered with. The same predicate ends the wait and produces the result.
The sequence is assigned inside the critical section the predicate uses. On the
gRPC side the counter increment moved into the same block as the insert, since a
flush reading the counter between them would have found a request counted and
not present.
Ordering across a wrap is a distance and not a comparison, and what has to stay
under half the range is how many sequences are handed out while the request being
asked about is alive, which the concurrency limit does not bound. At size_t width
that was reachable on 32 bit: a request holding sequence zero while another slot
completes 2^31 requests falls one past the half range and is skipped, where
comparing lifetime totals answers correctly. So the sequence is std::uint64_t,
which makes the OTLP HTTP client a new user of 64 bit atomics. It now calls
otel_link_libatomic, and its pkg-config file carries EXTRA_LIBS with the detected
atomic library, both of which the gRPC client already had. The generator emits
only what EXTRA_LIBS lists and does not read a target's link dependencies, so a
consumer with curl disabled, linking through pkg-config --static, would otherwise
be left with an undefined __atomic_fetch_add_8.
The gRPC completion callback now drops running_requests under the same lock as
the erase. While the flush read finished_request_counter that did not matter,
because the counter is bumped after the decrement; once the erase is what a flush
sees, a flush could report success in between while the next Export was still
refused for capacity.
finished_session_counter_ and finished_request_counter lose all their readers and
are removed.
One case per client drives the public ForceFlush: a later request finishing
while the original is pending must not satisfy it. That fails three runs of three
on main, on both the result and the duration, returning at 210 ms against a 500 ms
deadline for HTTP and at 200 ms against 1000 ms for gRPC. Both arrange the
ordering with a sleep, which is safe here: if it is reordered the flush is entered
with both requests pending, it waits, and that is what the case asserts, so it
passes without measuring rather than failing.
The other direction cannot be arranged that way, because asserting success fails
when a reordering puts the later request inside the snapshot, and nothing a test
can observe says when the cutoff was read. So it is asked of the predicate
directly, in two sequential cases with no threads, through the fixture that
OtlpHttpClient now friends, as otlp_http_exporter.h already does for that same
fixture. One completes the later request and asserts the snapshot is still not
satisfied; the other completes the original while the later one is in flight and
asserts that it is. The split matters: whichever request is completed first is no
longer in the registry for the other question, and a single sequence covering both
passed against a flush that waited for the whole registry to empty. With the split
that mutant is killed.
Both sequential cases finish whatever is still registered on the way out. Every
assertion in them runs before either request completes, and ~OtlpHttpClient waits
for the registry to empty with no deadline, so a fatal assertion would otherwise
hang rather than fail. With the predicate forced to report done, the case fails
in under a second and names the line. The guard lives in an anonymous namespace,
since a helper in a test translation unit has no reason to have external
linkage.
The gRPC predicate cannot be reached the same way, since it is a free function in
an anonymous namespace and its counter lives in a struct defined in the .cc, so
only the end to end case covers that client.
Full suite green with the async export preview on and off, 1525 cases each, and
in an HTTP build without gRPC, 1479. Clean under OTELCPP_MAINTAINER_MODE with
-Werror. ThreadSanitizer reports the same four warnings before and after on the
gRPC side, all inside libgrpc and libabsl, with no frame in this change and no
lock order inversion.
Refs open-telemetry/opentelemetry-cpp issue 4339
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
0 commit comments