Skip to content

fix: defer EventLoopThread teardown off DbLoop to avoid self-join - #2556

Open
wangshuo-wsws wants to merge 5 commits into
drogonframework:masterfrom
wangshuo-wsws:fix/dbclient-eventloop-self-join-2552
Open

fix: defer EventLoopThread teardown off DbLoop to avoid self-join#2556
wangshuo-wsws wants to merge 5 commits into
drogonframework:masterfrom
wangshuo-wsws:fix/dbclient-eventloop-self-join-2552

Conversation

@wangshuo-wsws

Copy link
Copy Markdown
Contributor

Summary

Fixes std::system_error / “Resource deadlock avoided” when the last DbClient / SQLite connection / PgListener reference is released from inside its own EventLoopThread callback (#2552).

~EventLoopThread calls thread_.join(). If that destructor runs on the same worker thread (via a completion lambda holding the last shared_ptr), join() throws and the process aborts.

  • Heap-allocate EventLoopThread / EventLoopThreadPool so ownership can be moved off the loop thread
  • When destroying from isInLoopThread(), hand the handle to a short-lived helper thread that performs the real teardown and join()

Touches DbClientImpl, Sqlite3Connection, and PgListener (same hazard on each).

Test plan

Closes #2552

harleywilsoneng added 5 commits August 14, 2026 18:58
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
@an-tao

an-tao commented Aug 17, 2026

Copy link
Copy Markdown
Member

@harleywilsoneng Thanks so much for your patch. I've made a PR an-tao/trantor#408 for that issue, please check it out.

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.

EventLoopThread self-join in DbClientImpl teardown when last ref released from own DbLoop thread (throws Resource deadlock avoided)

2 participants