cpdt / mini-io-queue

Fixed-length, allocation and lock-free, async I/O oriented single-producer single-consumer (SPSC) queues.
MIT License
3 stars 0 forks source link

panic created in ring.rs #1

Open vortex314 opened 10 months ago

vortex314 commented 10 months ago

Not sure how this issue happens but I got a panic in ring.rs. I'm running this crate with embassy to create an actor framework on a tm4c123 micro controller. Panic ->

panicked at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mini-io-queue-0.2.0/src/ring.rs:136:9:
len was larger than left region length

The code of the read side , running within a with_timeout of embassy..

    async fn recv(&mut self) -> CMD {
        let mut cmd = [CMD::default()];
    //    let cnt = self.cmds_reader.read(&mut cmd).await;
        let r = self.cmds_reader.read_exact(&mut cmd).await;
        if r.is_err() {
            warn!("recv error {:?}", r);
        } else {
        }
 //       self.cmds_reader.consume(cnt);
        cmd[0].clone()
    }

The writer is doing a block_on execution.

    fn on(&mut self, cmd: &CMD) {
        let buf = [cmd.clone()];
        if block_on(self.cmds_writer.write(&buf)) == 0 {
            warn!(" cannot write command ")
        };
    }

Any suggestion , to find the root cause ?

vortex314 commented 10 months ago

The rest of the code is located at : https://github.com/vortex314/tiva-rs https://github.com/vortex314/tiva-rs/commit/4829072bf4308b869874f015f912a3896a272e1b


Program received signal SIGTRAP, Trace/breakpoint trap.
lib::__bkpt () at asm/lib.rs:51
51      asm/lib.rs: No such file or directory.
(gdb) bt
#0  lib::__bkpt () at asm/lib.rs:51                                                                                                                 
#1  0x0001360c in cortex_m::asm::bkpt () at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cortex-m-0.7.7/src/asm.rs:15          
#2  panic_semihosting::panic (info=0x2000684c) at src/lib.rs:84                                                                                     
#3  0x0001cc3e in core::panicking::panic_fmt () at library/core/src/panicking.rs:72                                                                 
#4  0x00013018 in mini_io_queue::ring::Ring::advance_left (self=0x20000700, len=1) at src/ring.rs:136                                               
#5  0x0000f13a in mini_io_queue::asyncio::Reader<mini_io_queue::storage::heap_buffer::HeapBuffer<tiva_rs::led::LedCmd>>::consume<mini_io_queue::storage::heap_buffer::HeapBuffer<tiva_rs::led::LedCmd>> (self=0x200007dc, amt=1)                                                                        
    at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mini-io-queue-0.2.0/src/asyncio.rs:338                                     
#6  0x0000fde2 in mini_io_queue::asyncio::{impl#4}::poll<tiva_rs::led::LedCmd, mini_io_queue::storage::heap_buffer::HeapBuffer<tiva_rs::led::LedCmd>> (self=..., cx=0x20007ef4) at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mini-io-queue-0.2.0/src/asyncio.rs:490             
#7  0x0000ecf6 in mini_io_queue::asyncio::{impl#1}::read_exact::{async_fn#0}<mini_io_queue::storage::heap_buffer::HeapBuffer<tiva_rs::led::LedCmd>, tiva_rs::led::LedCmd> () at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mini-io-queue-0.2.0/src/asyncio.rs:388                
#8  0x00001672 in tiva_rs::limero::{impl#0}::recv::{async_fn#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent> () at src/limero/mod.rs:94          
#9  0x000021a4 in tiva_rs::limero::{impl#0}::process_message::{async_fn#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent> ()                       
    at src/limero/mod.rs:197                                                                                                                        
#10 0x00001210 in core::future::future::{impl#1}::poll<&mut tiva_rs::limero::{impl#0}::process_message::{async_fn_env#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent>> (self=..., cx=0x20007ef4) at /rustc/9a66e4471f71283fd54d80ef8147630d34756332/library/core/src/future/future.rs:125            
#11 0x000011c0 in futures_util::future::future::FutureExt::poll_unpin<core::pin::Pin<&mut tiva_rs::limero::{impl#0}::process_message::{async_fn_env#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent>>> (self=0x20000138 <tiva_rs::__embassy_main::POOL+264>, cx=0x20007ef4)                           
    at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.29/src/future/future/mod.rs:558                           
#12 0x0000c9e6 in futures_util::future::select::{impl#1}::poll<core::pin::Pin<&mut tiva_rs::limero::{impl#0}::process_message::{async_fn_env#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent>>, embassy_time::timer::Timer> (self=..., cx=0x20007ef4)                                                 
    at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.29/src/future/select.rs:114                               
#13 0x0000cc4e in embassy_time::timer::with_timeout::{async_fn#0}<tiva_rs::limero::{impl#0}::process_message::{async_fn_env#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent>> () at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-time-0.1.5/src/timer.rs:23              
#14 0x00002698 in tiva_rs::limero::{impl#0}::run::{async_fn#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent> () at src/limero/mod.rs:218          
#15 0x00002e8a in tiva_rs::limero::{impl#1}::run::{async_fn#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent> () at src/limero/mod.rs:259          
#16 0x0000992c in embassy_futures::select::{impl#3}::poll<tiva_rs::limero::{impl#1}::run::{async_fn_env#0}<tiva_rs::button::ButtonCmd, tiva_rs::button::ButtonEvent>, tiva_rs::limero::{impl#1}::run::{async_fn_env#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent>, tiva_rs::limero::{impl#1}::run::{async_fn_env#0}<tiva_rs::button::ButtonCmd, tiva_rs::button::ButtonEvent>, tiva_rs::limero::{impl#1}::run::{async_fn_env#0}<tiva_rs::led::LedCmd, tiva_rs::limero::NoEvent>> (self=..., cx=0x20007ef4)                                                                                                 
    at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-futures-0.1.0/src/select.rs:176                                    
#17 0x0000a18c in tiva_rs::____embassy_main_task::{async_fn#0} () at src/main.rs:280                                                                
#18 0x000050d0 in embassy_executor::raw::TaskStorage<tiva_rs::____embassy_main_task::{async_fn_env#0}>::poll<tiva_rs::____embassy_main_task::{async_fn_env#0}> (p=...) at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/raw/mod.rs:161                   
#19 0x00019dac in embassy_executor::raw::{impl#9}::poll::{closure#0} (p=...) at src/raw/mod.rs:411                                                  
#20 0x000197c2 in embassy_executor::raw::run_queue::RunQueue::dequeue_all<embassy_executor::raw::{impl#9}::poll::{closure_env#0}> (                 
    self=0x20007fdc, on_task=...) at src/raw/run_queue.rs:85                                                                                        
#21 0x00019d16 in embassy_executor::raw::SyncExecutor::poll (self=0x20007fdc) at src/raw/mod.rs:391                                                 
#22 0x00019e06 in embassy_executor::raw::Executor::poll (self=0x20007fdc) at src/raw/mod.rs:532                                                     
#23 0x0000ea82 in embassy_executor::arch::thread::Executor::run<tiva_rs::__cortex_m_rt_main::{closure_env#0}> (self=0x20007fdc, init=...)           
    at /home/lieven/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.3.0/src/arch/cortex_m.rs:107                            
#24 0x0000102a in tiva_rs::__cortex_m_rt_main () at src/main.rs:93                                                                                  
#25 0x0000100e in tiva_rs::__cortex_m_rt_main_trampoline () at src/main.rs:93                                                                       
(gdb)