Commit 22412f403a for asterisk.org
commit 22412f403a6195959f42d43085fa4c54ddb85edd
Author: Daniel Sullivan <danielsullivan87@gmail.com>
Date: Mon Aug 17 16:48:42 2026 +0900
res_audiosocket: Bound idle poll retries while reading header
Stop retrying after a few idle polls when no header bytes have been
read, and return a null frame so the caller can service its write
queue. Behavior is unchanged once a partial header has been read.
Resolves: #2078
Resolves: #2089
UserNote: An AudioSocket peer that stops sending data without closing
the connection no longer stalls outbound audio on the channel.
DeveloperNote: ast_audiosocket_receive_frame_with_hangup() may now
return &ast_null_frame when no header data arrives within a short
idle period.
diff --git a/res/res_audiosocket.c b/res/res_audiosocket.c
index 165035a0b6..39d0b6ba9f 100644
--- a/res/res_audiosocket.c
+++ b/res/res_audiosocket.c
@@ -44,6 +44,9 @@
#define MAX_CONNECT_TIMEOUT_MSEC 2000
+/*! \brief Maximum consecutive idle polls tolerated before a header read yields. */
+#define IDLE_POLL_MAX 4
+
/*!
* \internal
* \brief Attempt to complete the audiosocket connection.
@@ -288,6 +291,7 @@ struct ast_frame *ast_audiosocket_receive_frame_with_hangup(const int svc,
int *const hangup)
{
int i = 0, n = 0, ret = 0;
+ unsigned int idle_polls = 0;
struct ast_frame f = {
.frametype = AST_FRAME_VOICE,
.src = "AudioSocket",
@@ -312,6 +316,9 @@ struct ast_frame *ast_audiosocket_receive_frame_with_hangup(const int svc,
continue;
} else if (poll_result == 0) {
ast_debug(1, "Poll timed out while waiting for header data\n");
+ if (i == 0 && ++idle_polls > IDLE_POLL_MAX) {
+ return &ast_null_frame;
+ }
continue;
} else {
ast_log(LOG_WARNING, "Poll error: %s\n", strerror(errno));
@@ -324,6 +331,7 @@ struct ast_frame *ast_audiosocket_receive_frame_with_hangup(const int svc,
if (n == 0) {
break;
}
+ idle_polls = 0;
i += n;
}