Skip to content

fix: reduce memory usage in the mailserver#7523

Merged
jrainville merged 4 commits into
release/10.34.xfrom
fix/bg-service-dying
Jun 8, 2026
Merged

fix: reduce memory usage in the mailserver#7523
jrainville merged 4 commits into
release/10.34.xfrom
fix/bg-service-dying

Conversation

@jrainville

@jrainville jrainville commented Jun 5, 2026

Copy link
Copy Markdown
Member

Part status-im/status-app#21142

  • Reduce resume-time backend pressure by throttling historic sync requests in messenger_mailserver.go.

  • Keep functional behavior intact: still request historic messages on resume/availability triggers, but avoid repeated bursts.

  • Add mutex-guarded sync gate on RequestAllHistoricMessages:

    • skip when another historic sync is already in progress
    • skip when the previous request is within historicSyncMinInterval
    • clear in-flight state with deferred unlock path
  • Place throttling after existing sync preconditions (shouldSync, mailserversDatabase), so startup early-exit paths do not consume the throttle window.

  • Applied a minimal, low-risk optimization to reduce backend memory usage during background historic sync.

  • Kept existing public behavior unchanged for normal/API-triggered sync calls.

  • Added an internal path that skips building and merging MessengerResponse payloads when results are not needed.

  • Wired the async background trigger to use that non-aggregating path.

status-app PR: status-im/status-app#21159

Part status-im/status-app#21142

- Reduce resume-time backend pressure by throttling historic sync requests in messenger_mailserver.go.
- Keep functional behavior intact: still request historic messages on resume/availability triggers, but avoid repeated bursts.
- Add mutex-guarded sync gate on `RequestAllHistoricMessages`:
  - skip when another historic sync is already in progress
  - skip when the previous request is within `historicSyncMinInterval`
  - clear in-flight state with deferred unlock path
- Place throttling after existing sync preconditions (`shouldSync`, `mailserversDatabase`), so startup early-exit paths do not consume the throttle window.
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

✅ Companion PR Verified

#21159 - fix: reduce memory usage in the backend

@status-im-auto

status-im-auto commented Jun 5, 2026

Copy link
Copy Markdown
Member

Jenkins Builds

Click to see older builds (10)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 515da6a 1 2026-06-05 17:41:16 ~4 min linux/status-go 📦zip
✔️ 515da6a 1 2026-06-05 17:42:59 ~5 min windows/status-go 📦zip
✔️ 515da6a 1 2026-06-05 17:43:06 ~5 min macos/status-go 📦zip
✔️ 515da6a 1 2026-06-05 18:01:42 ~24 min tests-rpc 📄log
✔️ 515da6a 1 2026-06-05 18:15:54 ~38 min tests 📄log
✔️ 2a1c309 2 2026-06-05 18:22:03 ~4 min linux/status-go 📦zip
✔️ 2a1c309 2 2026-06-05 18:22:58 ~5 min macos/status-go 📦zip
✔️ 2a1c309 2 2026-06-05 18:23:08 ~5 min windows/status-go 📦zip
✖️ 2a1c309 2 2026-06-05 18:39:29 ~21 min tests-rpc 📄log
✔️ 2a1c309 2 2026-06-05 18:51:35 ~33 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 0dcaba0 3 2026-06-05 18:29:28 ~3 min linux/status-go 📦zip
✔️ 0dcaba0 3 2026-06-05 18:30:19 ~4 min macos/status-go 📦zip
✔️ 0dcaba0 3 2026-06-05 18:31:14 ~5 min windows/status-go 📦zip
✔️ c679f07 4 2026-06-05 18:39:16 ~4 min linux/status-go 📦zip
✔️ c679f07 4 2026-06-05 18:39:56 ~4 min macos/status-go 📦zip
✔️ c679f07 4 2026-06-05 18:40:43 ~5 min windows/status-go 📦zip
✔️ c679f07 3 2026-06-05 18:54:07 ~14 min tests-rpc 📄log
✔️ c679f07 3 2026-06-05 19:25:29 ~33 min tests 📄log

@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.46154% with 14 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/10.34.x@a0d2a0d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
protocol/messenger_mailserver.go 78.12% 11 Missing and 3 partials ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             release/10.34.x    #7523   +/-   ##
==================================================
  Coverage                   ?   61.27%           
==================================================
  Files                      ?      850           
  Lines                      ?   119093           
  Branches                   ?        0           
==================================================
  Hits                       ?    72969           
  Misses                     ?    38652           
  Partials                   ?     7472           
Flag Coverage Δ
functional 40.25% <78.46%> (?)
unit 55.25% <41.53%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
protocol/messenger.go 61.83% <ø> (ø)
protocol/messenger_mailserver_cycle.go 69.67% <100.00%> (ø)
protocol/messenger_mailserver.go 43.76% <78.12%> (ø)

… needed

- Applied a minimal, low-risk optimization to reduce backend memory usage during background historic sync.
- Kept existing public behavior unchanged for normal/API-triggered sync calls.
- Added an internal path that skips building and merging MessengerResponse payloads when results are not needed.
- Wired the async background trigger to use that non-aggregating path.
@jrainville

Copy link
Copy Markdown
Member Author

I added a second commit that's a quick win to reduce background memory usage. See commit description

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 reduces backend pressure by preventing overlapping and overly-frequent historic message sync requests, primarily around resume/store-node availability triggers in the Messenger mailserver sync flow.

Changes:

  • Add a mutex-guarded in-flight flag and minimum interval tracking to gate historic sync requests.
  • Refactor RequestAllHistoricMessages into an internal helper that can optionally skip aggregating responses (used by async calls).
  • Update the async historic sync path to call the internal helper without aggregation.

Reviewed changes

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

File Description
protocol/messenger.go Adds state (mutex, in-flight flag, last request timestamp) to support throttling/gating historic sync requests.
protocol/messenger_mailserver.go Implements the throttle + in-flight gate and refactors historic sync entrypoints to support optional response aggregation.
protocol/messenger_mailserver_cycle.go Switches async historic sync to call the new internal helper without aggregating responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread protocol/messenger_mailserver.go Outdated
Comment thread protocol/messenger_mailserver.go Outdated
@jrainville

Copy link
Copy Markdown
Member Author

And a final small change that should help a little bit by pre-sizing the maps to the right size

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

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

@jrainville jrainville changed the title fix: make sure historic syncs don't overlap or arent fired too often fix: reduce memory usage in the mailserver Jun 5, 2026
@caybro
caybro requested a review from alexjba June 8, 2026 08:16

@caybro caybro 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.

LGTM

@jrainville
jrainville merged commit 8213ddd into release/10.34.x Jun 8, 2026
22 of 25 checks passed
@jrainville
jrainville deleted the fix/bg-service-dying branch June 8, 2026 17:36
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.

[Android] Background service can crash and then the app becomes unusable

4 participants