From 6c840886a9e3da51a6d7810f4267cd16d7ce4593 Mon Sep 17 00:00:00 2001 From: Naveen Albert Date: Thu, 3 Oct 2024 17:33:39 -0400 Subject: [PATCH] app_dial: Fix progress timeout. Under some circumstances, the progress timeout feature added in commit 320c98eec87c473bfa814f76188a37603ea65ddd does not work as expected, such as if there is no media flowing. Adjust the waitfor call to explicitly use the progress timeout if it would be reached sooner than the answer timeout to ensure we handle the timers properly. Resolves: #821 (cherry picked from commit 62b6ea32022597ea6a922cb5f2e5f5b9e2e4435f) --- apps/app_dial.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/app_dial.c b/apps/app_dial.c index d38dd646c8..3861787b89 100644 --- a/apps/app_dial.c +++ b/apps/app_dial.c @@ -1271,7 +1271,6 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct cause_args num = *num_in; int prestart = num.busy + num.congestion + num.nochan; int orig_answer_to = *to_answer; - int progress_to_dup = *to_progress; int orig_progress_to = *to_progress; struct ast_channel *peer = NULL; struct chanlist *outgoing = AST_LIST_FIRST(out_chans); @@ -1316,7 +1315,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL); - while ((*to_answer = ast_remaining_ms(start, orig_answer_to)) && (*to_progress = ast_remaining_ms(start, progress_to_dup)) && !peer) { + while ((*to_answer = ast_remaining_ms(start, orig_answer_to)) && (*to_progress = ast_remaining_ms(start, orig_progress_to)) && !peer) { struct chanlist *o; int pos = 0; /* how many channels do we handle */ int numlines = prestart; @@ -1348,7 +1347,10 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, } SCOPE_EXIT_RTN_VALUE(NULL, "%s: No outgoing channels available\n", ast_channel_name(in)); } - winner = ast_waitfor_n(watchers, pos, to_answer); + + /* If progress timeout is active, use that if it's the shorter of the 2 timeouts. */ + winner = ast_waitfor_n(watchers, pos, *to_progress > 0 && *to_progress < *to_answer ? to_progress : to_answer); + AST_LIST_TRAVERSE(out_chans, o, node) { int res = 0; struct ast_frame *f; @@ -1565,7 +1567,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, */ ++num_ringing; *to_progress = -1; - progress_to_dup = -1; + orig_progress_to = -1; if (ignore_cc || cc_frame_received || num_ringing == numlines) { ast_verb(3, "%s is ringing\n", ast_channel_name(c)); /* Setup early media if appropriate */ @@ -1610,7 +1612,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, } } *to_progress = -1; - progress_to_dup = -1; + orig_progress_to = -1; if (!sent_progress) { struct timeval now, then; int64_t diff; @@ -1802,7 +1804,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, break; } *to_progress = -1; - progress_to_dup = -1; + orig_progress_to = -1; /* Fall through */ case AST_FRAME_TEXT: if (single && ast_write(in, f)) { -- 2.47.2