This only reproduces on a Kubuntu 21.10 x86_64 machine. It does not reproduce on other machines running Debian 10 or 11. It also did not reproduce previously on the same machine when it was running Kubuntu 21.04. So it looks like this issue is triggered by something that comes with Kubuntu 21.10.
I have prepared a reduced test case that reproduced the issue on Kubuntu 21.10.
I have tried running the test under gdb and I can see that the code is waiting for the connection listening thread to terminate. I can see in gdb output that the thread actually terminates (gdb prints "[Thread 0x7ffff4f3d640 (LWP 133542) exited]" as soon as you press Enter), but the wait does not end until timeout. On timeout the process aborts with the following backtrace:
assert.cxx(114) PWLib Assertion fail: Listener thread did not terminate, file transports.cxx, line 1321, Error=20
Assertion fail: Listener thread did not terminate, file transports.cxx, line 1321, Error=20
Dumping core.
Thread 1 "h323_hang_test" received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=140737303301760) at pthread_kill.c:44
44 pthread_kill.c: No such file or directory.
(gdb) thread apply all bt
Thread 2 (Thread 0x7ffff4f7e640 (LWP 133541) "h323_hang_test"):
#0 __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555673090) at futex-internal.c:57
#1 __futex_abstimed_wait_common (cancel=true, private=0, abstime=0x0, clockid=0, expected=0, futex_word=0x555555673090) at futex-internal.c:87
#2 __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x555555673090, expected=expected@entry=0, clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=private@entry=0) at futex-internal.c:139
#3 0x00007ffff6b8b920 in __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x555555673040, cond=0x555555673068) at pthread_cond_wait.c:504
#4 ___pthread_cond_wait (cond=0x555555673068, mutex=0x555555673040) at pthread_cond_wait.c:628
#5 0x00007ffff73c2507 in PSyncPoint::Wait (this=0x555555673028) at ptlib/unix/tlibthrd.cxx:1719
#6 0x00007ffff7c04330 in H323ConnectionsCleaner::Main (this=0x555555672f20) at /home/lastique/src/xcoder/master/external/libh323plus/h323plus/src/h323ep.cxx:661
#7 0x00007ffff73bf3dd in PThread::PX_ThreadStart (arg=0x555555672f20) at ptlib/unix/tlibthrd.cxx:495
#8 0x00007ffff6b8c927 in start_thread (arg=<optimized out>) at pthread_create.c:435
#9 0x00007ffff6c1c9e4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100
Thread 1 (Thread 0x7ffff4f84e80 (LWP 133537) "h323_hang_test"):
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737303301760) at pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=140737303301760) at pthread_kill.c:80
#2 __GI___pthread_kill (threadid=140737303301760, signo=signo@entry=6) at pthread_kill.c:91
#3 0x00007ffff6b3a476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x00007ffff6b207b7 in __GI_abort () at abort.c:79
#5 0x00007ffff73f4809 in PAssertAction (c=67, msg=0x55555566f950 "Assertion fail: Listener thread did not terminate, file transports.cxx, line 1321, Error=20") at ptlib/unix/assert.cxx:81
#6 0x00007ffff73f4a21 in PAssertFunc (msg=0x55555566f950 "Assertion fail: Listener thread did not terminate, file transports.cxx, line 1321, Error=20") at ptlib/unix/assert.cxx:164
#7 0x00007ffff7440759 in PAssertFunc (file=0x7ffff7d6c35b "transports.cxx", line=1321, className=0x0, msg=0x7ffff7dae3b8 "Listener thread did not terminate") at ptlib/common/object.cxx:147
#8 0x00007ffff7bd90e4 in PAssertFuncInline (b=false, file=0x7ffff7d6c35b "transports.cxx", line=1321, className=0x0, msg=0x7ffff7dae3b8 "Listener thread did not terminate") at /home/lastique/xcoder-usr/include/ptlib/object.h:182
#9 0x00007ffff7c59d17 in H323ListenerTCP::Close (this=0x555555673260) at /home/lastique/src/xcoder/master/external/libh323plus/h323plus/src/transports.cxx:1321
#10 0x0000555555564b3b in endpoint::terminate() ()
#11 0x0000555555563a9a in main ()
I'm using ptlib 2.10.9.4 and libh323plus 1.27.2, both with minor patches updating build system and code for compatibility with our system (some of them are based on the upstream commits made after the released library versions). I'm fairly certain that the patches are not the problem as they have been tested before and don't cause problems on Debian.
I'm not quite sure if the problem is in ptlib or libh323plus, but it looks like threading code is in ptlib, and that is likely where the problem lies, hence I'm reporting it to ptlib.