Hi,

I've stumble upon a problem with a specific sequence of expiring,
stopping and (re)starting tw timers.

In pseudo C code the pattern is

Lets assume some kind of timer in a session gets started with:

session->timer[0] =  tw_timer_start (tw, interval_a);
session->timer[1] =  tw_timer_start (tw, interval_b);
...
session->timer[n] =  tw_timer_start (tw, interval_n);

while (42) {
  tw_timer_expire (tw, expired);

  foreach (e, expired) {
    session = session_from_timer_id(e);

    foreach (t, session->timer) {
      if (t->timer_id != INVALID_ID)
        tw_timer_stop (tw, t->timer_id);
      t->timer_id = tw_timer_start (tw, interval);
    }
 }

With this sequence, tw_timer_stop might stop the wrong timer.

The problem is that tw_timer_expire removes the timer from its
internal pool. The timer_id itself is now invalid, but the timer_id
stored in the external session timer data structure is not cleared.
The following stop will find the timer_id and try to stop it. The
following start will lead to the use of a new pool entry from the
wheels internal pool.
What can happen is that a pool entry release by tw_timer_expire is
reused in the loop by tw_timer_start only to be erroneously stopped by
tw_timer_stop in a later iteration of the inner loop.

Is the above explanation understandable and/or disagrees anyone with
the conclusion?

After finding the problem in my code, I wanted to see what VPP is
doing. And it seems that at least the SCTP timer code handling has
this exact issue.

Regards
Andreas
-- 
Andreas Schultz

-- 

Principal Engineer

t: +49 391 819099-224

------------------------------- enabling your networks
-----------------------------

Travelping GmbH

Roentgenstraße 13

39108 Magdeburg

Germany

t: +49 391 819099-0

f: +49 391 819099-299

e: i...@travelping.com

w: https://www.travelping.com/


Company registration: Amtsgericht Stendal  Reg. No.: HRB 10578
Geschaeftsfuehrer: Holger Winkelmann VAT ID: DE236673780
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13440): https://lists.fd.io/g/vpp-dev/message/13440
Mute This Topic: https://lists.fd.io/mt/32307309/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to