http: run completed resolver callbacks on io executor

This commit is contained in:
Cyrille authored and Adrien Beraud committed 2026-07-15 13:13:22 -04:00
1 parent c8a948e2ea
commit 91fad057b7
1 file changed
+12 -2
+12 -2
View File
@@ -917,8 +917,18 @@ Resolver::add_callback(ResolverCb cb, sa_family_t family)
else
cb(ec, filter(endpoints, family));
});
else
cb(ec_, family == AF_UNSPEC ? endpoints_ : filter(endpoints_, family));
else {
// Always dispatch the callback on the io_context thread. Invoking it
// synchronously would run the caller's continuation (e.g. the whole
// connect chain of Request::send) on the calling thread, mutating asio
// objects concurrently with the io thread running the io_context.
asio::post(resolver_.get_executor(),
[cb = std::move(cb),
ec = ec_,
endpoints = family == AF_UNSPEC ? endpoints_ : filter(endpoints_, family)] {
cb(ec, endpoints);
});
}
}
void