Skip to content

fix: clear hasPendingWork queue before shutdown on multiple node types to prevent corruption - #2673

Open
NickDunklee wants to merge 4 commits into
meshcore-dev:devfrom
NickDunklee:shutdown-contact-sync-pending-work
Open

fix: clear hasPendingWork queue before shutdown on multiple node types to prevent corruption#2673
NickDunklee wants to merge 4 commits into
meshcore-dev:devfrom
NickDunklee:shutdown-contact-sync-pending-work

Conversation

@NickDunklee

@NickDunklee NickDunklee commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This PR is a cleanup and is in ref to my comments in #2627

Update: This PR has been updated so it can still be merged, as it is still relevant to clearing pending work before shutdown to try and prevent corruption during power off - which was different from another PR mentioned in comments. It also fixed some minor messaging text for consistency.

@ripplebiz had some recommendations for existing code flows, so I refactored to leverage that. It compiles against a few sensor/repeater/companion node types, but I haven't tested it yet.

  • hasPendingWork() extended so simple_repeater and companion_radio both gate sleep and shutdown for pending contact writes, however, existing behavior with certain displayless companions that have no AUTO_SHUTDOWN_MILLIVOLTS, no power checks, no power paths will still just run until the board dies - probably room for future improvements there
  • shutdown loops using hasPendingWork instead of ShutdownHandler idea in previous PR
  • UITask shutdown behavior - both variants (ui-new, ui-tiny) now set a _wants_shutdown flag instead of calling powerOff() directly
  • Shutdown language across shutdown text standardized with "..." for user-commanded and "!" for forced due to low power
  • "all" eInk displays will send a final "Shut Down" message so the displays show "Shut Down" after a successful shutdown rather than the last message being "shutting down"
  • I also removed my code in this PR that is in pull 2627 so they are both separate PRs - missed that in the fever-dream editing.

@disq

disq commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

PR title doesn't fully reflect the changes. Also some of it is similar to #2663

@NickDunklee

NickDunklee commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Updating here for read consistency - that other PR disables auto-shutdown on powered nodes. This PR makes sure contacts are synced before the node powers off to prevent corruption.

Thanks @disq ! 🤜 🤛

  - hasPendingWork() extended so simple_repeater and
    companion_radio both gate sleep and shutdown for
    pending contact writes
  - shutdown loops using hasPendingWork instead of ShutdownHandler
    idea in previous PR
  - uiTask shutdown behavior - all three variants (ui-new,
    ui-tiny, ui-orig) now set a _wants_shutdown flag instead of
    calling powerOff() directly
  - "Power off in 5 seconds…" messages added everywhere a
    shutdown is announced
  - "all" (hopefully) eInk displays are now tagged together
    using isEInk() constant
  - "all" eInk displays will send a final "Shut Down" message
    so the displays show "Shut Down" after a successful shutdown
  - removed display text from ui-orig as none of those paths
    have displays
  - changed text formatting/syntax across all strings to match
    - low power, "!"
    - user-chosen or otherwise, "..."
  - removed mention of 5 seconds since it could be 0-5 seconds
    to shutdown after contact flush
@NickDunklee
NickDunklee force-pushed the shutdown-contact-sync-pending-work branch from f6e2bc9 to f16c496 Compare June 5, 2026 21:50
@NickDunklee

Copy link
Copy Markdown
Contributor Author

Updated to take into account recent dev changes, removed some code that would never be executed, and cleaned up messaging.

@NickDunklee NickDunklee changed the title fix: contact sync across simple_repeater and companion_radio fix: clear hasPendingWork before shutdown on multiple node types Jun 5, 2026
@NickDunklee

Copy link
Copy Markdown
Contributor Author

Update: #2663 was about disabling power off when on mains power. This PR is about a different failure mode: making sure a manual/physical shutdown doesn't cut power while a contact-list write is still pending in the 5s lazy-write window (dirty_contacts_expiry), which can corrupt the contact list.

@NickDunklee NickDunklee changed the title fix: clear hasPendingWork before shutdown on multiple node types fix: clear hasPendingWork queue before shutdown on multiple node types Aug 7, 2026
@NickDunklee NickDunklee changed the title fix: clear hasPendingWork queue before shutdown on multiple node types fix: clear hasPendingWork queue before shutdown on multiple node types to prevent corruption Aug 7, 2026
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