Skip to content

fix(ear): messages can't be displayed - WPB-24136#4450

Open
David-Henner wants to merge 3 commits intorelease/cycle-4.16from
fix/sync-cancellation-issues
Open

fix(ear): messages can't be displayed - WPB-24136#4450
David-Henner wants to merge 3 commits intorelease/cycle-4.16from
fix/sync-cancellation-issues

Conversation

@David-Henner
Copy link
Contributor

@David-Henner David-Henner commented Mar 18, 2026

BugWPB-24136 [iOS] Messages can't be displayed due to decryption errors

Issue

Sometimes, with EAR enabled, after opening the app, some messages can't be displayed.

Screenshot 2026-03-18 at 11 53 24

Cause

Messages couldn't be encrypted at rest because the database key was missing.

This happens because the app went to the background and locked the database (nullified the database key from cache) while the incremental sync was running and processing messages.

When this happens, we cancel the sync

However, the cancellation doesn't get propagated properly from the suspend method to the inner sync task. Hence, the sync continues and tries to process messages while the database key is nil

Solution

  • Propagate task cancellation properly in NonReentrantTaskManager and ExpiringActivity
  • Add a Task.checkCancellation before processing individual events in the incremental sync

Testing

  1. Log in & Enable EAR
  2. Put the app in the background
  3. Receive many messages (use a spambot to send 100s of messages)
  4. Open the app and immediately put it in the background once the sync starts
  5. Reopen the app

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

)

for envelope in envelopes {
try Task.checkCancellation()
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: if we processed some events, then cancel, we won't delete any of the events already processed, so next time the sync happens some events will be processed again. I think in the case of new message events this is fine as we have tolerance to reprocess such events. But I'm not sure that all events are like this.

Though... now I'm wondering if this is the case since we don't hit the databaseSaver.save() line. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

55ec7a0

In this commit:

  • Added logic to handle the interruption of event processing, in order to delete processed events and save the database.
  • Replaced Task.checkCancellation by throwing when the database is locked and the envelope isn't background accessible. The reasoning is that if there's an ongoing call when going to the background, we don't cancel the sync, so the database key would be removed from cache but we'd continue processing events that require it

I think it starts to make the sync too complex with special cases for EAR, and another idea I had was to systematically cancel the sync when going to the background. And, in case there's an ongoing call, start a call events only sync.

What do you think ?

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 65166ca.

Summary: workflow run #23242108485
Allure report (download zip): html-report-28616-fix_sync-cancellation-issues

@sonarqubecloud
Copy link

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