Feature: logging and exitcodes styfry sync (#124)#193
Merged
hoytech merged 2 commits intohoytech:masterfrom Apr 15, 2026
Merged
Conversation
Owner
|
Thanks! |
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.
Description
This PR addresses three issues reported in #124 related to the
strfry synccommand hanging indefinitely, oversized event content leaking into logs, and unhelpful error handling when connecting to relays that do not support negentropy.Changes included:
Inactivity Timeout for
strfry sync:--timeout=<seconds>CLI flag tocmd_sync.cpp. When set, the sync process aborts with exit code 1 if no WebSocket activity is observed for the specified duration.hoytech::timer(the same pattern used byRelayCronandcmd_router) with a 1-second tick andstd::atomic<uint64_t> lastActivityupdated on everyonConnectandonMessageevent.ws.trigger()→ws.onTriggerto ensure the exit runs on the WebSocket thread, consistent with the existingcmd_stream.cpptrigger pattern.0(disabled) for full backward compatibility.NOTICE Error Detection:
NOTICEmessage handler incmd_sync.cpp. If aNOTICEis received before anyNEG-MSGresponse (tracked bybool receivedNegMsg), and the notice text matches common error keywords (case-insensitive), the sync exits with code 1 and a clear log message indicating the relay likely does not support negentropy."ERROR: negentropy disabled","bad message type","Command unrecognized", etc. caused the sync process to hang indefinitely.Remove Event Content from Rejection Logs (
WriterPipeline.h):Rejected event <id>: <reason>. Falls back to"unknown"if the ID cannot be parsed.WriterPipeline(sync, import, router).Truncate Large Messages in Error Paths:
cmd_sync.cppnow truncate the raw message string to 512 characters, preventing unbounded log growth from malformed or adversarial relay messages.Related Issue
Closes #124
Motivation and Context
Users running
strfry syncin automated pipelines against many relays encountered processes hanging indefinitely when relays did not support the negentropy protocol (NIP-77). These relays send a human-readableNOTICEinstead of aNEG-ERR, leavingstrfry syncwaiting forever with no way to detect the failure. The--timeoutflag and NOTICE detection together ensure the process always terminates with a meaningful exit code. Additionally, the rejection logging change eliminates a disk-fill vector that could be triggered by any client sending oversized events to a relay running sync or import.How Has This Been Tested?
Functionally tested against live Nostr relays in WSL Ubuntu:
--timeoutflag verified present in--helpoutput and confirmed it does not fire during an active sync against a responsive relay (relay.damus.io).nos.lolandnostr.mom(both respond with"ERROR: bad msg: negentropy disabled"): sync exits with code 1 within ~1 second instead of hanging.relay.damus.ioproduce log lines of the formRejected event <hex_id>: event too large: <size>with no event content.make.Types of changes
Checklist:
CHANGESfile).