la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock #15
Merged
ClaudeAI
merged 1 commits from fix/la-serva-memory-leaks into master 15 minutes ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'fix/la-serva-memory-leaks'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Summary
Fixes the memory and descriptor leaks found in the la_serva review (
Projects/la_serva,Debug86), plus crashes, memory corruption and a deadlock on the database log.Leaks that grew without bound
servaRPCHadnlerdrops a connection that sends nothing forRPC_IDLE_TIMEOUT_S(60 s; la_mojo sends a status about every second). Accepted sockets also get TCP keepalive (30 s idle, 3 probes of 10 s).accept()hitEMFILE, the accept thread ended for good.~serverPortshuts down and closes the socket;accept()errors (EMFILE,ENFILE,ENOMEM,ECONNABORTED,EINTR, and others) no longer stop the server;recv() == 0always counts as a disconnect.servaSessionManager::reopenSessionstored the reopened (expired) session in the per-track map, overwriting the track's active session. The active session's data and openreport.dbleaked, and it was never closed in MySQL. Reopened sessions are now kept outside the map and released by the caller.servaVideoComposerleaked its session data, an open SQLite connection and both video queues on every composition.servaKernel:compose()failed;Crashes and corruption
vector::erase()was followed by reuse of the old iterator in 7 loops: the network server, the encoder and composer pools, and 4 Modbus loops.transportSocket::_close:selecttimeout, which blocked the accept thread on every disconnect.Query()logs while holding the non-recursive DB mutex, and the log service wrote to the database synchronously. That deadlocks on the same thread and also between two threads.MySQL_Connector::TrySilentQuery, which never blocks and never logs;basicMutex::try_lockreturned true when the lock was not taken. An uncontendedtry_lockkept the mutex and the caller never released it. Notry_lockcall in la_mojo or la_serva is actually reached today (basicEngine::setWMonly uses it withhard == false, which no caller passes). The fix matters for other users such asobjectLGS,transportSerial,videoNodeandbasicVideoAnalyzer.EXIT_CODE_RELOAD_SERVICESdeleted the database object that every surviving component still used. It is now kept.module_id[4]for platforms with more than 4 modules;registerServAoverflowed a 120-byte stack buffer, closed apopen()stream withfclose, and leaked the config;servaBackendwere allocated one byte short;networkServerfreed libconfig's host string.Minor
DEBUG_EXTRAbuilds.Testing
Debug86sources passg++ -fsyntax-only. With-Wall, the changed files have no new warnings (servaKernel.cppwent from 16 to 12). The changed shared files still compile in la_mojo.networkServer/serverPort/transportSocketclasses, under AddressSanitizer (no findings):basicMutex::try_lock: checked free, held by another thread, and free again after unlock./proc/<pid>/taskand/proc/<pid>/fdover a day with module outages;Behaviour changes
Generated with Claude Code
https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
07d312e680.