Skip to content

fix(events): don't warn/stacktrace on a valid pre-generated handler id#323

Merged
csoler merged 1 commit into
RetroShare:masterfrom
jolavillette:fix/eventshandler-false-override-warning
Jul 8, 2026
Merged

fix(events): don't warn/stacktrace on a valid pre-generated handler id#323
csoler merged 1 commit into
RetroShare:masterfrom
jolavillette:fix/eventshandler-false-override-warning

Conversation

@jolavillette

@jolavillette jolavillette commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

fix(events): don't warn/stacktrace on a valid pre-generated handler id

registerEventsHandler() documents (rsevents.h) that the caller may pass an hId previously obtained from generateUniqueHandlerId(). The JSON API event-stream wrapper (jsonapi.cpp) does exactly this: it pre-generates the id so its SSE callbacks can capture it to unregister themselves, then passes it to registerEventsHandler().

The implementation treated any non-zero hId as an override, calling print_stacktrace() + "Overriding an existing error handler ID ... very unexpected". So every event-stream registration (every webui/mobile connection, plus each 5s reconnect and each 1MB queue restart) dumped a bogus stack trace to the log, contradicting the API's own contract.

Only warn when the hId is actually already present in the handler maps, i.e. a real override. A freshly generated id never is (ids are monotonic), so the false positive is gone while genuine accidental id reuse is still reported. Only jsonapi.cpp pre-generates ids; every other caller passes 0, so behaviour there is unchanged.

@csoler

csoler commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Very surprising PR: the check was added because it's very easy (due to a design flaw) to not initialize a handle ID and replace an existing one by mistake. Normally generateUniqueHandlerId() should be private so that it is only called by the register method itself. Besides, if you allow to bypass the call to generateUniqueHandlerId(), then mLastHandler will not be consistent with the existing list of Ids anymore.

@jolavillette jolavillette force-pushed the fix/eventshandler-false-override-warning branch 2 times, most recently from 519c163 to bad4758 Compare July 7, 2026 12:25
registerEventsHandler() documents (rsevents.h) that the caller may pass
an hId previously obtained from generateUniqueHandlerId(). The JSON API
event-stream wrapper (jsonapi.cpp) does exactly this: it pre-generates
the id so its SSE callbacks can capture it to unregister themselves,
then passes it to registerEventsHandler().

The implementation treated any non-zero hId as an override, calling
print_stacktrace() + "Overriding an existing error handler ID ... very
unexpected". So every event-stream registration (every webui/mobile
connection, plus each 5s reconnect and each 1MB queue restart) dumped a
bogus stack trace to the log, contradicting the API's own contract.

Only warn when the hId is actually already present in the handler maps,
i.e. a real override. A freshly generated id never is (ids are
monotonic), so the false positive is gone while genuine accidental id
reuse is still reported. Only jsonapi.cpp pre-generates ids; every other
caller passes 0, so behaviour there is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jolavillette jolavillette force-pushed the fix/eventshandler-false-override-warning branch from bad4758 to 01b8ac9 Compare July 7, 2026 22:03
@csoler csoler merged commit f655c6d into RetroShare:master Jul 8, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants