Skip to content

Propagate persistence restore failures - #571

Open
aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:fix/persistence-restore-failures
Open

Propagate persistence restore failures#571
aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:fix/persistence-restore-failures

Conversation

@aidangarske

Copy link
Copy Markdown
Member
F-8599

@aidangarske aidangarske self-assigned this Aug 12, 2026
Copilot AI lite review requested due to automatic review settings August 12, 2026 02:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves broker persistence restore reliability by ensuring backend restore/iteration failures are surfaced to the caller and by adding rollback logic to discard partially restored in-memory state.

Changes:

  • Propagate kv_iter/restore failures from BrokerPersist_Restore() instead of ignoring them, and rollback partially restored broker state on failure.
  • Add deferred deletion handling for legacy/invalid persisted sessions (e.g., session-expiry=0) to avoid mutating persistence backends during iteration.
  • Add unit tests covering iterator failure propagation, deferred delete behavior, and session key/body mismatch handling.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
wolfmqtt/mqtt_broker.h Declares BrokerPersist_RestoreRollback() for use across persistence/restore code.
src/mqtt_broker.c Implements restore rollback helper to free/clear partially restored broker state.
src/mqtt_broker_persist.c Propagates iterator failures during restore, defers deletes until after iteration, and tightens session/sub restore validation.
tests/test_broker_connect.c Adds persistence restore tests for error propagation and deferred delete semantics.
Suppressed comments (1)

src/mqtt_broker_persist.c:726

  • When session expiry is 0, this path ignores any failure from BrokerPersist_DelSubs and returns only the result of BrokerPersist_DelSession. That can report success even if subs deletion failed, leaving stale persisted subscriptions behind.
    if (session_expiry_sec == 0) {
        (void)BrokerPersist_DelSubs(broker, client_id);
        return BrokerPersist_DelSession(broker, client_id);
    }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #571

Scan targets checked: wolfmqtt-bugs, wolfmqtt-src

Findings: 8
8 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker_persist.c
Comment thread tests/test_broker_connect.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated
Comment thread tests/test_broker_connect.c Outdated
Comment thread tests/test_broker_connect.c Outdated
Comment thread src/mqtt_broker.c
@aidangarske
aidangarske force-pushed the fix/persistence-restore-failures branch from eccc130 to 874b407 Compare August 12, 2026 03:42
@aidangarske
aidangarske marked this pull request as ready for review August 12, 2026 19:09
@aidangarske
aidangarske requested a review from embhorn August 12, 2026 19:31

@embhorn embhorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skoll Code Review

Scan type: reviewOverall recommendation: REQUEST_CHANGES
Findings: 15 total — 15 posted, 0 skipped
15 finding(s) posted as inline comments (see file-level comments below)

Posted findings

  • [High] Restore silently drops persisted subscriptions whose SESSION record was skipped, breaking persistent-session resumesrc/mqtt_broker_persist.c:1669-1674
  • [Medium] Deferred zero-expiry cleanup turns a backend delete failure into a hard MqttBroker_Start() refusalsrc/mqtt_broker_persist.c:2251-2256
  • [Medium] "Put" functions now perform destructive cascading deletes; doc comments still describe them as write-onlysrc/mqtt_broker_persist.c:702-712,725-728
  • [Medium] Cleanup reports success when the backend implements no kv_del, defeating the PR's failure-propagation goalsrc/mqtt_broker_persist.c:1156-1162
  • [Medium] BrokerPersist_RestoreRollback() discards all broker state, not just what restore loadedsrc/mqtt_broker.c:6651-6684
  • [Medium] New restore semantics and the rollback path are under-testedtests/test_broker_connect.c:288-296,343-396
  • [Low] RestoreRollback duplicates the subs-teardown loop from MqttBroker_Free, and the two copies already differsrc/mqtt_broker.c:6663-6677
  • [Low] wmqb_log_client_id() duplicates BrokerLog_Sanitize() with a weaker, divergent escaping policysrc/mqtt_broker_persist.c:60-78
  • [Low] #ifndef blocks wrap only the opening and closing brace of an if statementsrc/mqtt_broker.c:5199-5207,5281-5289
  • [Info] struct wmqb_restore_ctx::delete_count is written but never readsrc/mqtt_broker_persist.c:1322
  • [Info] Restore log reports deleted= before the deletes have runsrc/mqtt_broker_persist.c:2241-2251
  • [Info] Unreachable session_expiry_sec==0 rejection in wmqb_restore_create_orphan reports a misleading error codesrc/mqtt_broker_persist.c:1418-1421
  • [Info] New header declaration lacks a doc comment and the persist-hook contract is now stalewolfmqtt/mqtt_broker.h:849
  • [Info] 128-byte stack buffer populated even in no-log buildssrc/mqtt_broker_persist.c:2061,2074
  • [Info] RestoreRollback does not reset broker-next_packet_idsrc/mqtt_broker.c:6655-6683

Review generated by Skoll

Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated
Comment thread src/mqtt_broker_persist.c Outdated
Comment thread wolfmqtt/mqtt_broker.h
Comment thread src/mqtt_broker_persist.c
Comment thread src/mqtt_broker.c Outdated
@aidangarske
aidangarske force-pushed the fix/persistence-restore-failures branch from 874b407 to 3a0c7b3 Compare August 13, 2026 18:17
@aidangarske
aidangarske requested a review from embhorn August 13, 2026 23:06
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.

4 participants