Repository navigation
fix(broker): log fatal errors, batch abuse saves in one transaction, add LOG_LEVEL - #7
Merged
Elektr0Vodka merged 1 commit intoOct 20, 2026
Conversation
…add LOG_LEVEL - add uncaughtException/unhandledRejection handlers that log the stack and exit(1) - add http/ws server error listeners (accept errors are logged, listen errors stay fatal) - wrap periodic timers (abuse save, stats publish) so a failed tick only logs - save trust states in one transaction with prepared statements, WAL + synchronous=NORMAL - add LOG_LEVEL (debug|info|warn|error, default logs everything); JWT token input only at debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The collector we run for meshcore-analyzer.eu (image built from 6e17036) exited with code 1 about 2.5 times a day for two weeks (38 restarts between 2026-10-05 and 2026-10-20), and failed its health check for minutes before each exit. The reason was never visible: there is no
uncaughtException/unhandledRejectionhandler, and at ~180 log lines/s the default 3 x 10 MB json-file rotation held about two hours, so every stack trace was gone before anyone looked. Details: EU-Meshcore-Analyzer issue 1193.What
src/server.ts): process-leveluncaughtExceptionandunhandledRejectionhandlers log[FATAL]with the full stack, thenexit(1)as before (the restart policy brings the broker back).errorlisteners on the HTTP server and the WebSocketServer: before listening (e.g.EADDRINUSE) stays fatal; after listening an error such as an accept-timeEMFILEis logged (throttled to one per 5 s) instead of becoming an uncaught exception.src/abuse-detector.ts): statements prepared once at init, the whole save in onedb.transaction,journal_mode = WALandsynchronous = NORMALat open. Before, every client was its ownINSERT OR REPLACEwith its own fsync, all synchronous on the event loop. Schema and loaded data are unchanged. The shutdown save uses the same path.LOG_LEVEL(src/logger.ts, README,.env.example):debug|info|warn|error. Unset = everything is logged exactly as today. Atinfothe per-publish and per-connection chatter is dropped ([STREAM] close()/destroy() called,Publish authorized,Published JWT payload,[PUBLISH] Internal ->, PING/PONG, connection details). Warnings, errors, denials, disconnect reasons and abuse events stay. The[AUTH] Token inputline (a full credential) and the token hex dump are debug-only.Checks
npx tsc --noEmitclean on main and on this branch.LOG_LEVELunset and once withinfo: ready line, TCP connect to the port succeeds, SIGTERM exits 0 with[ABUSE] Shutdown complete; the chatter lines appear only withoutLOG_LEVEL.[FATAL] Uncaught exception (uncaughtException): Error: forced test throwwith stack, exit code 1.Behaviour notes
-waland-shmfiles next to the abuse DB; the data volume must be writable (it already is for the DB itself).