chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.73k stars 1.2k forks source link

any_executor().query() segfaults instead of throwing bad_executor #1322

Closed ecatmur closed 11 months ago

ecatmur commented 1 year ago

Motivating example (incorrect, but an easy mistake to make):

asio::any_io_executor ex;
asio::ip::tcp::socket sock(ex);

Prior to https://github.com/chriskohlhoff/asio/commit/9d420678b4f89d20585f42f85deb0838e3597991 this would throw asio::execution::bad_executor; after that commit it just segfaults.

Online example using Boost.Asio (1.80 vs 1.81): https://godbolt.org/z/WGvMEWr8P

We noticed this because clang-tidy started warning that object_fns_ could be indirected while null.

Presumably query/require/prefer need to check for null target_ the same way execute does?

ecorm commented 12 months ago

I get clang-tidy warnings whenever I initialize strands and executors for this same reason. The warnings also occur with asio::any_completion_executor which I now use extensively.

ecatmur commented 11 months ago

Possibly fixed by 6c4a16680caa5e63e742f7041cf1fccaa30f1841, checking

ecatmur commented 11 months ago

Confirming fixed: https://godbolt.org/z/7c5PMchn3