Skip to content

Conversation

@andy-verida
Copy link
Contributor

@andy-verida andy-verida commented Jul 1, 2024

💭 What's changed?

Closes #1477
Notion: https://www.notion.so/verida/Wallet-Inbox-not-receiving-messages-ec2df6de2ffb4823bb7bcda06388c842

The problem and solution

Managing connections is more challenging on mobile devices as the app state can change and the OS can force disconnections. Mobile device internet connections change frequently.

The current way of managing connections from the protocol is quite good for dealing with desktop environments but not mobile devices. I think we need to add a healthCheck method for any live connection DBs and constantly perform checks at intervals. It's cheap to call the DB.info() method.

I'm unsure why the connections do not work in some cases, even when trying to reestablish them. We must re-initialize the DBs(Inbox), and in the worst case, soft restart the app to get the connections back.

Implementation:

  • Monitor network connectivity and app state changes, and activate the health check in case the connection state changes.
  • Add a healthCheck method: Perform health checks and reconnect attempts with a retry mechanism.
    • At the 3rd attempt, reinitialize InboxDB and do the health check
    • Last resort, after 10 failed attempts, restart the app.
  • Ensure the inbox is rebuilt if necessary, especially after prolonged background periods or connection failures.
  • Constantly perform health checks for the inbox.

Patch the client-ts by emitting an event INBOX_FAILED_TO_CONNECT

  • console.log("Retrying to establish public inbox connection");
    + inbox.emit('INBOX_FAILED_TO_CONNECT', {});
    

At this file https://github.com/verida/verida-js/blob/main/packages/client-ts/src/context/engines/verida/messaging/inbox.ts#L155-L158

This indicates the inbox is struggling to reconnect, especially on mobile devices where connections might be disconnected by the OS.

🧪 How to test these changes?

😨 Anything to be aware of?

@andy-verida andy-verida added bug Something isn't working enhancement New feature or request labels Jul 1, 2024
@andy-verida andy-verida self-assigned this Jul 1, 2024
@aurelticot aurelticot added optimisation and removed enhancement New feature or request labels Jul 3, 2024
@aurelticot aurelticot self-requested a review July 3, 2024 05:10
@aurelticot aurelticot linked an issue Jul 3, 2024 that may be closed by this pull request
@aurelticot aurelticot changed the title fix: fix inbox not receiving messages issue Optimise inbox to fix message receiption issues and disconnection Jul 3, 2024
@aurelticot aurelticot linked an issue Jul 3, 2024 that may be closed by this pull request
@aurelticot aurelticot added this to the 1.5.0 milestone Jul 3, 2024
@aurelticot aurelticot linked an issue Jul 3, 2024 that may be closed by this pull request
@andy-verida andy-verida marked this pull request as ready for review July 8, 2024 10:37
healthCheck()
initInboxMessaging()
// Listen for the inbox event that failed to connect from the SDK, and active the health check
inbox.on('INBOX_FAILED_TO_CONNECT', healthCheck)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Listening for the event INBOX_FAILED_TO_CONNECT from the protocol

@andy-verida andy-verida requested a review from tahpot July 9, 2024 04:41
@aurelticot aurelticot modified the milestones: 1.5.0, 1.6.0 Jul 11, 2024
@aurelticot aurelticot changed the title Optimise inbox to fix message receiption issues and disconnection Optimise inbox to fix message reception issues and disconnection Jul 17, 2024
@aurelticot aurelticot modified the milestones: 1.6.0, 1.x.x Apr 14, 2025
@aurelticot aurelticot removed their request for review September 10, 2025 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working optimisation

Projects

None yet

3 participants