Huge thread leak on Asterisk 16.2.1

Hello !

On two machines having exactly the same configuration (Debian 10/ Asterisk 16.2.1 installed w/apt) , I’m having the same problem:

Each call creates a new thread -which seems to be quite normal- but these threads won’t die at the end of the call. Therefore the number of sleeping threads continues growing until quickly reaching the 4915 limit defined in the systemd conf.

Once the limit is reached, all new calls are rejected with the following messages in asterisk logs :

Unable to create thread (returned error: 11)
Failed to create new channel thread

Here is the status of one of these threads which should be dead long time ago as the associated call is finished :

cat /proc/10938/task/24584/status
Name:   asterisk
Umask:  0022
State:  S (sleeping)
Tgid:   10938
Ngid:   0
Pid:    24584
PPid:   1
TracerPid:      0
Uid:    0       0       0       0
Gid:    0       0       0       0
FDSize: 512
NStgid: 10938
NSpid:  24584
NSpgid: 10938
NSsid:  10938
VmPeak:  7929744 kB
VmSize:  7929744 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:    872568 kB
VmRSS:    872568 kB
RssAnon:          841964 kB
RssFile:           30604 kB
RssShmem:              0 kB
VmData:  6090148 kB
VmStk:       144 kB
VmExe:      1980 kB
VmLib:     29392 kB
VmPTE:     12260 kB
VmSwap:        0 kB
HugetlbPages:          0 kB
CoreDumping:    0
Threads:        11444
SigQ:   4819/31797
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000008005003
SigIgn: 0000000000001000
SigCgt: 0000000181414003
CapInh: 0000000000000000
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000
NoNewPrivs:     0
Seccomp:        0
Speculation_Store_Bypass:       thread vulnerable
Cpus_allowed:   f
Cpus_allowed_list:      0-3
Mems_allowed:   00000000,00000001
Mems_allowed_list:      0
voluntary_ctxt_switches:        2584
nonvoluntary_ctxt_switches:     1

Any input would be greatly appreciated …

Retry with Asterisk 16.17.0.

(Is the channel still present? If so what dialplan command is it running?

If you obtain a backtrace, or enable thread debugging, is it waiting for something?

If the channel is no longer present, is there anything unusual in the logs at the time it should have terminated.)

I would try installing from source. Its as easy as installing from apt. You may also try the 18 branch as well.