CloseHandle and SAFE_CLOSE_HANDLE are empty off Windows, so the POSIX
receive thread is never released: nothing detaches it and nothing joins
it. Every IOCPClient keeps one thread for good, and each screen, file,
shell or log sub-connection constructs a fresh IOCPClient. Once the leak
reaches RLIMIT_NPROC, pthread_create returns EAGAIN, std::thread throws,
and OnServerReceiving's catch(...) swallows it: every command that spawns
a worker goes quiet while COMMAND_SYSTEM keeps working. Observed on a Mac
after six weeks: 2048 threads against a 1333 limit.
Detach the thread right after creation so it is reclaimed when it
returns; the destructor still waits on m_bWorkThread, so nothing else
changes. Also log the pthread_create failure that used to be silent, and
publish S_STOP as the very last write in WorkThreadProc: the destructor
reads it as "thread is gone" and frees this, so the m_bIsRunning that
used to follow it could land in freed memory.
Two smaller fixes on the same sub-connection path:
- common/sub_conn_thread.h never called SetDefaultProto, so sub-connects
fell back to plaintext TCP whatever g_SETTINGS.protoType said: behind a
reverse proxy the packet dies before the master (no [ConnAuth] on the
server, only "waiting for ack timed out" on the client). Android did.
- macos/main.mm and linux/main.cpp log the spawn before starting the
worker and catch std::system_error, reporting e.code().value() rather
than errno, which libc++/libstdc++ never set here. The macOS skeleton
also reports ConnectServer failures and a null createHandler.
Co-Authored-By: deepseek-flash