Skip to content

Release HttpClient on its loop after a DNS lookup - #2667

Open
StevSoested wants to merge 1 commit into
drogonframework:masterfrom
StevSoested:bugfix/2666-release-http-client-on-its-loop
Open

StevSoested wants to merge 1 commit into
drogonframework:masterfrom
StevSoested:bugfix/2666-release-http-client-on-its-loop

Conversation

@StevSoested

Copy link
Copy Markdown

Fixes #2666.

The callback given to the resolver holds a shared_ptr to the client. NormalResolver calls it on a thread of its own
and destroys it there, so that copy can be the client's last reference; ~HttpClientImpl() then runs on the resolver's
thread and uses the client's loop, which may be gone (heap corruption, SIGSEGV). This moves the reference into the work
handed to the loop, so the client is always let go of on its loop. Behaviour is otherwise unchanged: the client still
lives through the lookup, as before.

Tested:

  • The reproducer in the issue, 2000 runs 8 at a time on a busy machine: 131 crashes before, 0 after.
  • Our own test of an HTTP executor built on HttpClient, 300 runs each under the same load: 13 crashes before, 0 after.
  • Drogon's unit tests (ctest, 40 tests) pass. The integration test was not run here, as it listens on ports 80 and 443,
    which the test machine uses.

…n its loop after a DNS lookup

Updated lambda function to use mutable capture for 'thisPtr' and added comments for clarity.
@StevSoested StevSoested changed the title Release HttpClient on its loop after a DNS lookup Release HttpClient on its loop after a DNS lookup Nov 6, 2026
@StevSoested StevSoested closed this Nov 6, 2026
@StevSoested StevSoested reopened this Nov 6, 2026

This branch has not been deployed

No deployments
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.

HttpClient can be destroyed on the resolver's thread and then use an event loop that is gone

1 participant