Skip to content

[TEST] Cancel from the IO thread in the curl cancel cases - #4376

Merged
marcalff merged 2 commits into
open-telemetry:mainfrom
thc1006:test/curl-cancel-on-io-thread
Aug 7, 2026
Merged

marcalff merged 2 commits into
open-telemetry:mainfrom
thc1006:test/curl-cancel-on-io-thread

Conversation

@thc1006

@thc1006 thc1006 commented Aug 6, 2026

Copy link
Copy Markdown
Member

Fixes #4369. The client side is #4375, which this does not touch.

ACancelBeforeTheResponseReportsCancelled cancelled from the test thread while the IO thread was driving the easy handle, so TSAN saw Abort()'s curl_easy_setopt against Curl_resolv. Per your note, this works around it in the test and leaves the client to the other issue.

What it does instead

Nothing listens on 19937, so the connection fails and PerformCurlMessage dispatches ConnectFailed from the IO thread. Cancelling from that event still leaves the state short of Response with the abort flag raised, which is what the completion callback's WasAborted() arm needs, and Abort() now runs on the thread that owns the handle. The sibling case already cancelled from OnEvent(Response), which was on the IO thread too, so both are consistent now.

It also drops the mtx_requests hold, since the case no longer needs to keep the server quiet.

It still covers what it was written for

The point of the case is the else if (operation.WasAborted()) arm, which nothing exercised before it and which Codecov had flagged. Deleting that arm still turns it red:

Expected equality of these values:
  1
  handler->cancelled_from_callback_.load(std::memory_order_acquire)
    Which is: 0

Cancelled is still counted by its empty reason rather than by any cancel, since Cleanup() dispatches one of its own carrying a curl message and GetCurlErrorMessage never returns an empty string. One difference worth noting: on this path Cleanup() sees ConnectFailed rather than an in flight state, so it does not add a second Cancelled, and the total is one instead of two.

Both cases now record the thread they cancelled on and assert it is not the test thread, so a later edit cannot move the cancel back to the caller without failing.

Checks

22 of 22 in curl_http_test against unmodified main, clang-format clean, clean under OTELCPP_MAINTAINER_MODE=ON. Three TSAN runs of the two cases are clean, though I would not read much into that: I could not reproduce the original race here either, twelve runs including one aimed at a slow resolving host.

No CHANGELOG.md entry, since nothing user visible changes.

ACancelBeforeTheResponseReportsCancelled cancelled from the test thread
while the IO thread was driving the easy handle, and TSAN caught Abort's
curl_easy_setopt against Curl_resolv. The client side is open-telemetry#4375.

Nothing listens on 19937, so the connection fails and PerformCurlMessage
dispatches ConnectFailed from the IO thread. Cancelling there still
leaves the state short of Response with the abort flag raised, which is
what the completion callback's WasAborted arm needs, and Abort now runs
on the thread that owns the handle.

Both cases record the thread they cancelled on and assert it is not the
test thread, so a later edit cannot move it back without failing.

@marcalff marcalff 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.

LGTM, thanks for the fix.

@marcalff marcalff added the issue:blocking This issue is preventing other fixes label Aug 7, 2026
@marcalff

marcalff commented Aug 7, 2026

Copy link
Copy Markdown
Member

Added blocking label: this fix needs to merge, to restore a working CI for tsan builds.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.77%. Comparing base (57bf864) to head (153de86).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4376   +/-   ##
=======================================
  Coverage   81.77%   81.77%           
=======================================
  Files         493      493           
  Lines       19456    19456           
=======================================
  Hits        15909    15909           
  Misses       3547     3547           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcalff
marcalff merged commit 5cfda3c into open-telemetry:main Aug 7, 2026
72 checks passed
@thc1006
thc1006 deleted the test/curl-cancel-on-io-thread branch August 7, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

issue:blocking This issue is preventing other fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TSAN detected race in BasicCurlHttpTests.ACancelBeforeTheResponseReportsCancelled

2 participants