Skip to content

[branch-4.0][fix](be) Init thread context on AsyncIO worker threads#65271

Merged
morningman merged 1 commit into
apache:branch-4.0from
liaoxin01:codex/pick-64846-to-branch-4.0
Jul 7, 2026
Merged

[branch-4.0][fix](be) Init thread context on AsyncIO worker threads#65271
morningman merged 1 commit into
apache:branch-4.0from
liaoxin01:codex/pick-64846-to-branch-4.0

Conversation

@liaoxin01

Copy link
Copy Markdown
Contributor

Pick #64846

`FILESYSTEM_M` dispatches IO ops from a bthread to an `AsyncIO` worker
pthread that is **not bound to any task** and therefore has no
`ThreadContext`. When the dispatched `fn()` reads a local file, it goes
through `LocalFileReader::read_at_impl` -> `LIMIT_LOCAL_SCAN_IO` ->
`thread_context()`, which raises `Status::FatalError` (aborting the BE
in debug/ASAN builds) when no `ThreadContext` exists.

Observed as a Cloud P0 coredump on the load error-log S3 upload path:

```
RuntimeState::get_error_log_file_path()
  -> _s3_error_fs->upload()                 (called from a bthread)
  -> AsyncIO::run_task() on an AsyncIO worker pthread (no attached task)
  -> S3FileSystem::upload_impl()
  -> LocalFileReader::read_at_impl()
  -> LIMIT_LOCAL_SCAN_IO -> thread_context() -> FatalError -> SIGABRT
```

Initialize an (unattached) `ThreadContext` at the `AsyncIO` worker
boundary via `SCOPED_INIT_THREAD_CONTEXT()`, the same pattern used by
StorageEngine background threads. This gives every `thread_context()`
consumer running on an AsyncIO worker (memory tracking,
`LIMIT_*_SCAN_IO`, ...) a valid context, fixing the crash at its root
rather than making individual consumers tolerate a missing context.
@liaoxin01 liaoxin01 requested a review from morningman as a code owner July 6, 2026 11:37
Copilot AI review requested due to automatic review settings July 6, 2026 11:37
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Copilot AI left a comment

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.

Pull request overview

This PR backports #64846 to ensure AsyncIO’s pthread-based worker threads have a valid ThreadContext before running dispatched filesystem work, preventing fatal failures when worker-side code touches thread_context() (e.g., memory tracking / IO limiting helpers).

Changes:

  • Add runtime/thread_context.h include to AsyncIO header.
  • Initialize an (unattached) ThreadContext inside AsyncIO thread-pool task execution via SCOPED_INIT_THREAD_CONTEXT().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread be/src/util/async_io.h
@liaoxin01

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.51% (19561/36559)
Line Coverage 36.57% (182990/500353)
Region Coverage 33.15% (142311/429320)
Branch Coverage 34.00% (61499/180905)

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.51% (25578/35767)
Line Coverage 54.39% (271248/498696)
Region Coverage 52.01% (225080/432752)
Branch Coverage 53.42% (96867/181327)

@morningman morningman merged commit 8251b44 into apache:branch-4.0 Jul 7, 2026
30 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants