chriskohlhoff / asio

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

execution_context::shutdown blocks indefinitely with ASIO_HAS_IO_URING_AS_DEFAULT #1327

Open cjbradfield opened 1 year ago

cjbradfield commented 1 year ago

I have a custom execution context that calls asio::execution_context::shutdown followed by destroy() as per the recommendations in the documentation. All sockets in the system are closed and no pending completions. However, when shutting down the execution context the program will occasionally block forever with the following callstack:

(gdb) bt                                                                                                                                                                                                                   
#0  0x0000559b4ce0d1d6 in ____sys_io_uring_enter2 (fd=3, to_submit=0, min_complete=1, flags=1, sig=0x0, sz=8) at arch/x86/../syscall-defs.h:62
#1  0x0000559b4ce0d495 in _io_uring_get_cqe (ring=0x615000000ff0, cqe_ptr=0x7ffd5adb7be0, data=0x7ffd5adb7b10) at queue.c:95                                                                                                                                                
#2  0x0000559b4ce0d55c in __io_uring_get_cqe (ring=0x615000000ff0, cqe_ptr=0x7ffd5adb7be0, submit=0, wait_nr=1, sigmask=0x0) at queue.c:124 
#3  0x0000559b4cb535d4 in io_uring_wait_cqe_nr (ring=0x615000000ff0, cqe_ptr=0x7ffd5adb7be0, wait_nr=1) at /home/chrisb/.conan/data/liburing/2.2/_/_/package/1ff654795aff0e2fc08046c6dc84fe20833f3363/include/liburing.h:985                                                                                                   
#4  0x0000559b4cb53d28 in io_uring_wait_cqe (ring=0x615000000ff0, cqe_ptr=0x7ffd5adb7be0) at /home/chrisb/.conan/data/liburing/2.2/_/_/package/1ff654795aff0e2fc08046c6dc84fe20833f3363/include/liburing.h:1058
#5  0x0000559b4cb6a236 in asio::detail::io_uring_service::shutdown (this=0x615000000f80)  at /home/chrisb/.conan/data/asio/1.28.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/asio/detail/impl/io_uring_service.ipp:97 
#6  0x0000559b4cacb80f in asio::detail::service_registry::shutdown_services (this=0x606000017f00)  at /home/chrisb/.conan/data/asio/1.28.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/asio/detail/impl/service_registry.ipp:43
#7  0x0000559b4cacbf98 in asio::execution_context::shutdown (this=0x60b0000000f0) at /home/chrisb/.conan/data/asio/1.28.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/asio/impl/execution_context.ipp:40

All async objects (acceptors and sockets in this case) at this point are closed with no pending async operations (all completions have fired). Everything always shuts down cleanly when using the epoll_reactor. This is on ASIO 1.28.0.