async-book icon indicating copy to clipboard operation
async-book copied to clipboard

Expecting a panic on max queued tasks

Open cannero opened this issue 6 years ago • 1 comments

In the chapter 'Applied: Build an Executor' we set MAX_QUEUED_TASKS and have an expect on send(task) which should fail if there are too many tasks. I tried to trigger this panic by setting MAX_QUEUED_TASKS to 1 and spawn the async function for TimerFuture two times. However the program just hangs. By setting the max queued tasks to 2, it works.

I'm on windows, if it helps here is the stack trace for the main thread:

[0x0] ntdll!NtWaitForAlertByThreadId + 0x14
[0x1] ntdll!RtlSleepConditionVariableSRW + 0x130
[0x2] KERNELBASE!SleepConditionVariableSRW + 0x2d
[0x3] async_prog!std::sys::windows::c::SleepConditionVariableSRW + 0x3e
[0x4] async_prog!std::sys::windows::condvar::Condvar::wait + 0x3e
[0x5] async_prog!std::sys_common::condvar::Condvar::wait + 0x3e
[0x6] async_prog!std::sync::condvar::Condvar::wait + 0x58
[0x7] async_prog!std::thread::park + 0x1ab
[0x8] async_prog!std::sync::mpsc::blocking::WaitToken::wait + 0x25
[0x9] async_prog!std::sync::mpsc::sync::Packet<alloc::sync::Arc<async_prog::simple_executor::Task>>::acquire_send_slot<alloc::sync::Arc<async_prog::simple_executor::Task>> + 0x19d
[0xa] async_prog!std::sync::mpsc::sync::Packet<alloc::sync::Arc<async_prog::simple_executor::Task>>::send<alloc::sync::Arc<async_prog::simple_executor::Task>> + 0x48
[0xb] async_prog!std::sync::mpsc::SyncSender<alloc::sync::Arc<async_prog::simple_executor::Task>>::send<alloc::sync::Arc<async_prog::simple_executor::Task>> + 0x42
[0xc] async_prog!async_prog::simple_executor::Spawner::spawn<std::future::GenFuture> + 0xad
[0xd] async_prog!async_prog::use_timer_future + 0x9b
[0xe] async_prog!async_prog::main::{{closure}} + 0x36
[0xf] async_prog!std::future::{{impl}}::poll::{{closure}} + 0x1d
[0x10] async_prog!std::future::set_task_context<closure-1,core::task::poll::Poll<()>> + 0x73
[0x11] async_prog!std::future::{{impl}}::poll + 0x36
[0x12] async_prog!tokio::runtime::enter::Enter::block_on<std::future::GenFuture> + 0x15e
[0x13] async_prog!tokio::runtime::thread_pool::ThreadPool::block_on<std::future::GenFuture> + 0x44
[0x14] async_prog!tokio::runtime::{{impl}}::block_on::{{closure}}<std::future::GenFuture> + 0xb7
[0x15] async_prog!tokio::runtime::context::enter<closure-0,()> + 0x6b
[0x16] async_prog!tokio::runtime::handle::Handle::enter<closure-0,()> + 0x56
[0x17] async_prog!tokio::runtime::Runtime::block_on<std::future::GenFuture> + 0x47
[0x18] async_prog!async_prog::main + 0xbd
[0x19] async_prog!std::rt::lang_start::{{closure}}<()> + 0x10
[0x1a] async_prog!std::rt::lang_start_internal::{{closure}} + 0xc
[0x1b] async_prog!std::panicking::try::do_call<closure-0,i32> + 0x17
[0x1c] async_prog!panic_unwind::__rust_maybe_catch_panic + 0x22
[0x1d] async_prog!std::panicking::try + 0x33
[0x1e] async_prog!std::panic::catch_unwind + 0x33
[0x1f] async_prog!std::rt::lang_start_internal + 0x102
[0x20] async_prog!std::rt::lang_start<()> + 0x3b
[0x21] async_prog!main + 0x20
[0x22] async_prog!invoke_main + 0x22
[0x23] async_prog!__scrt_common_main_seh + 0x10c
[0x24] KERNEL32!BaseThreadInitThunk + 0x14
[0x25] ntdll!RtlUserThreadStart + 0x21

cannero avatar Feb 09 '20 17:02 cannero

The program hangs because the thread gets into a deadlock. I fixed it at #189

honzuki avatar Jan 31 '23 20:01 honzuki