zeromq / czmq

High-level C binding for ØMQ
czmq.zeromq.org
Mozilla Public License 2.0
1.16k stars 523 forks source link

zloop allows calling start() again but timer removal fails then #2278

Closed veimmone closed 2 months ago

veimmone commented 4 months ago

The terminated member in _zloop_t is only used in zloop_timer_end to check whether the timer can be removed immediately or via the zombie list.

The terminated member is initialized to false in zloop_new through zmalloc. It is set to true before returning from zloop_start.

Now, if you call zloop_start again on the same zloop_t object, terminated is still true, and then if you call zloop_timer_end from a reactor callback, you end up touching self->timers against the warning on line 581 in zloop.c.

Judging by the test suite, calling zloop_start repeatedly is a valid use case.

The fix seems simple enough; self->terminated = false; before the main reactor loop in zloop_start.

sphaero commented 4 months ago

can you send a PR?

veimmone commented 3 months ago

My colleague found the time to spearhead making the PR: https://github.com/zeromq/czmq/pull/2282