kgiusti commented on a change in pull request #1170:
URL: https://github.com/apache/qpid-dispatch/pull/1170#discussion_r625124660



##########
File path: src/timer.c
##########
@@ -110,16 +174,37 @@ qd_timer_t *qd_timer(qd_dispatch_t *qd, qd_timer_cb_t cb, 
void* context)
 void qd_timer_free(qd_timer_t *timer)
 {
     if (!timer) return;
+
     sys_mutex_lock(lock);
-    timer_cancel_LH(timer);
-    DEQ_REMOVE(idle_timers, timer);
+
+    assert(timer->state != QD_TIMER_STATE_DELETED);  // double free!!!
+
+    if (timer->state == QD_TIMER_STATE_RUNNING) {
+        if (sys_thread_self() != callback_thread) {
+            // Another thread is running the callback (see qd_timer_visit())
+            // Wait until the callback finishes
+            timer->state = QD_TIMER_STATE_BLOCKED;
+            sys_cond_wait(timer->condition, lock);

Review comment:
       Timers are executed sequentially, not in parallel.  This is by design to 
avoid races between timer callbacks.  A 10 second timer handler would cause all 
timers scheduled to expire after it to be blocked for 10 seconds and miss their 
deadlines regardless of this patch.
   
   Timer callbacks are meant to run quickly and should not block.  Long running 
events must be scheduled as background tasks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to