Skip to content

fix(executor): support destruction from worker threads - #233

Merged
lxy-9602 merged 1 commit into
apache:mainfrom
mrdrivingduck:codex/fix_default_executor_shutdown
Aug 28, 2026
Merged

fix(executor): support destruction from worker threads#233
lxy-9602 merged 1 commit into
apache:mainfrom
mrdrivingduck:codex/fix_default_executor_shutdown

Conversation

@mrdrivingduck

Copy link
Copy Markdown
Contributor

What does this PR do?

While testing the OSS filesystem asynchronous read path, we found a lifecycle issue in DefaultExecutor. The issue is not OSS-specific: S3 asynchronous reads use the same ownership pattern and can trigger it as well.

The sequence is:

  1. An asynchronous object-store request submits a task that captures a shared_ptr to its client.
  2. The caller releases its client reference.
  3. A worker completes the task and releases the final client reference.
  4. The client and its executor are then destroyed on that worker thread.
  5. Executor shutdown tries to join() the current worker thread.

Without this fix, joining the current thread throws std::system_error with Resource deadlock avoided. Since this happens during destruction, it can terminate the process.

This PR separates the executor's shared scheduling state from the executor object. Workers retain the shared state rather than accessing the executor through this. When destruction happens on a worker, shutdown stops the shared state, joins the other workers, and detaches the current one. The current worker then finishes its task and exits normally.

The PR adds a generic executor regression test and an S3 asynchronous range-read test covering this lifecycle.

@mrdrivingduck
mrdrivingduck force-pushed the codex/fix_default_executor_shutdown branch from 29b72fb to 9d7ba65 Compare August 21, 2026 06:04
@mrdrivingduck
mrdrivingduck marked this pull request as ready for review August 21, 2026 07:00
@mrdrivingduck
mrdrivingduck force-pushed the codex/fix_default_executor_shutdown branch 5 times, most recently from 71f6a98 to bbd4a84 Compare August 25, 2026 11:51
@lucasfang

Copy link
Copy Markdown
Collaborator

Thanks for your contribution. The core fix is correct and effective. Moving the scheduling state into a shared_ptr so that workers never touch this, combined with detach() when the thread being shut down is the current one, is the right approach — both parts are necessary, since detaching without relocating the state would leave the surviving worker touching freed members.

Comment thread src/paimon/common/executor/executor.cpp
Decouple worker state from the executor object so that a task can safely
destroy its final executor owner from a worker thread.

Serialize shutdown so concurrent callers cannot attempt to join the same
worker.

Co-authored-by: GPT-5.6 Terra <codex@users.noreply.github.com>
@mrdrivingduck
mrdrivingduck force-pushed the codex/fix_default_executor_shutdown branch from bbd4a84 to e6f4fce Compare August 27, 2026 16:57
@lucasfang

Copy link
Copy Markdown
Collaborator

+1

@lxy-9602 lxy-9602 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.

+1 Thank you for your patience!

@lxy-9602
lxy-9602 merged commit 8644975 into apache:main Aug 28, 2026
16 checks passed
@mrdrivingduck
mrdrivingduck deleted the codex/fix_default_executor_shutdown branch August 28, 2026 14:04
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.

3 participants