The experimental Asterisk 22.5.1 AMI accept-path fix from section 7.3. Test servers only. Apply in the Asterisk source tree with patch -p1, then rebuild and install the binary (make main; only main/asterisk changes). 1. main/tcptls.c: the listen backlog of Asterisk's TCP servers (the AMI among them) 10 -> 1024. 2. main/manager.c: purge_old_stuff(), which runs on every pass of the AMI accept loop and locks every session, at most once a second. --- a/main/tcptls.c +++ b/main/tcptls.c @@ -880,7 +880,7 @@ strerror(errno)); goto error; } - if (listen(desc->accept_fd, 10)) { + if (listen(desc->accept_fd, 1024)) { /* VICIfast: was 10 */ ast_log(LOG_ERROR, "Unable to listen for %s!\n", desc->name); goto error; } --- a/main/manager.c +++ b/main/manager.c @@ -9094,6 +9094,14 @@ static void purge_old_stuff(void *data) { struct ast_tcptls_session_args *ser = data; + /* VICIfast: this runs on every pass of the AMI accept loop and locks every session in turn, so a busy + * AMI starves accept() and the listen queue overflows. Check at most once a second unless purging. */ + static struct timeval vf_last; + struct timeval vf_now = ast_tvnow(); + if (ser->poll_timeout != 1 && ast_tvdiff_ms(vf_now, vf_last) < 1000) { + return; + } + vf_last = vf_now; /* purge_sessions will return the number of sessions actually purged, * up to a maximum of it's arguments, purge one at a time, keeping a * purge interval of 1ms as long as we purged a session, otherwise