--- app_queue.c.orig 2006-05-05 09:51:01.000000000 +1200 +++ app_queue.c 2006-05-05 10:01:23.000000000 +1200 @@ -2171,7 +2171,10 @@ free(tmp); } } - to = (qe->parent->timeout) ? qe->parent->timeout * 1000 : -1; + if (qe->expire && (!qe->parent->timeout || (qe->expire - now) <= qe->parent->timeout)) + to = (qe->expire - now) * 1000; + else + to = (qe->parent->timeout) ? qe->parent->timeout * 1000 : -1; ring_one(qe, outgoing, &numbusies); ast_mutex_unlock(&qe->parent->lock); if (use_weight)