// TODO(wesleyac): Fix race
//
// There is a potential race in the following condition:
//
// 1. Timer is set
// 2. Ethernet event gets enqueued
// 3. Timer future fires (enqueueing timer message - timer has _not_ been cancelled yet)
// 4. Ethernet event gets handled. This attempts to reschedule the timer into the future.
// 5. Timer message gets handled - event is triggered as if it happened at a time in the
//    future!
//
// The fix to this should be to have the event loop drain the queue without yielding, thus
// ensuring that the timer future cannot fire until the main queue is empty.
// See `GroupAvailable` in `src/connectivity/wlan/wlanstack/src/future_util.rs`
// for an example of how to do this.
Fix race
There is a potential race in the following condition.

1. Timer is set
2. Ethernet event gets enqueued
3. Timer future fires (enqueueing timer message - timer has _not_ been cancelled yet)
4. Ethernet event gets handled. This attempts to reschedule the timer into the future.
5. Timer message gets handled - event is triggered as if it happened at a time in the
future!

The fix to this should be to have the event loop drain the queue without yielding, thus
ensuring that the timer future cannot fire until the main queue is empty.
Fix race There is a potential race in the following condition . 1 . Timer is set 2 . Ethernet event gets enqueued 3 . Timer future fires ( enqueueing timer message - timer has _not_ been cancelled yet ) 4 . Ethernet event gets handled . This attempts to reschedule the timer into the future . 5 . Timer message gets handled - event is triggered as if it happened at a time in the future! The fix to this should be to have the event loop drain the queue without yielding thus ensuring that the timer future cannot fire until the main queue is empty .
fn cancel_timeout(&mut self, id: TimerId) -> Option<Instant> {
        let index =
            self.timers.iter().enumerate().find_map(
                |x| {
                    if x.1.id == id {
                        Some(x.0)
                    } else {
                        None
                    }
                },
            )?;
        self.timers[index].abort_handle.abort();
        Some(self.timers.remove(index).time)
    }
fn cancel_timeout ( & mut self , id : TimerId ) -> Option < Instant > { let index = self . timers . iter ( ) . enumerate ( ) . find_map ( | x | { if x . 1 . id == id { Some ( x . 0 ) } else { None } } , ) ? ; self . timers [ index ] . abort_handle . abort ( ) ; Some ( self . timers . remove ( index ) . time ) }
TODO(wesleyac): Fix race
There is a potential race in the following condition:
TODO ( wesleyac ) : Fix race There is a potential race in the following condition :
&mut self
id
TimerId