Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi forking root saga #1970

Open
kingalg opened this issue Oct 16, 2023 · 6 comments
Open

Multi forking root saga #1970

kingalg opened this issue Oct 16, 2023 · 6 comments
Assignees
Labels
bug Something isn't working mobile

Comments

@kingalg
Copy link
Collaborator

kingalg commented Oct 16, 2023

Version: [email protected]
System: iOS and android (but less common)

What happen - user is stuck at thee beginning of joining proces after very specific conditions are fulfilled

Steps to recreate:

  1. Have an app with already registered user and Leave Community (this step is crucial as it won't happen with freshly installed app)
  2. Change screen "join community" to "create community"
  3. Put the app in the background
  4. Try to join with QR code

App should recognize that this is the code to join community and proceed with the usual flow)

Edit: Initially I thought that it happens only on ios but I've spotted it on android as well, even without changing to "create community".

Edit2 (29 Nov): it happens especially often when the user leaves and tries to re-join community.

@kingalg kingalg added bug Something isn't working iOS labels Oct 16, 2023
@kingalg kingalg added this to Quiet Oct 16, 2023
@kingalg kingalg moved this to Backlog - Mobile in Quiet Oct 16, 2023
@kingalg kingalg changed the title Corner case - problems with joining from QR code on iOS Problems with joining from QR code Oct 16, 2023
@holmesworcester holmesworcester moved this from Backlog - Mobile to Next Sprint in Quiet Oct 16, 2023
@siepra siepra added react-native and removed iOS labels Nov 23, 2023
@siepra siepra moved this from Next Sprint to Sprint in Quiet Nov 29, 2023
@siepra siepra moved this from Sprint to In progress in Quiet Nov 29, 2023
@siepra siepra self-assigned this Nov 29, 2023
@siepra siepra moved this from In progress to Waiting for review in Quiet Nov 29, 2023
@siepra siepra moved this from Waiting for review to Merged (develop) in Quiet Nov 29, 2023
@Kacper-RF Kacper-RF moved this from Merged (develop) to (Mobile) Ready for QA in Quiet Dec 1, 2023
@kingalg
Copy link
Collaborator Author

kingalg commented Dec 4, 2023

@siepra I didn't notice any improvement in [email protected] (iOS 340). Do you have some other ideas what may be causing this problems?

@siepra siepra moved this from (Mobile) Ready for QA to In progress in Quiet Dec 4, 2023
@siepra siepra moved this from In progress to Next Sprint in Quiet Dec 7, 2023
@siepra siepra moved this from Next Sprint to In progress in Quiet Dec 7, 2023
@siepra siepra added the 2.1.x label Dec 7, 2023
@siepra
Copy link
Contributor

siepra commented Dec 7, 2023

Initially I thought it was the problem with web socket client connection, but it's actually the problem with redux persist being purged when leaving community.

EDIT: I performed tests including commenting out pausing, flushing and purging redux persist. It seemed to make no impact

@siepra siepra moved this from In progress to Waiting for review in Quiet Dec 14, 2023
@siepra siepra mentioned this issue Dec 14, 2023
4 tasks
@holmesworcester holmesworcester changed the title Problems with joining from QR code Problems with re-joining community mobile Jan 2, 2024
@holmesworcester
Copy link
Contributor

holmesworcester commented Jan 2, 2024

This will affect users leaving and rejoining communities who do not "swipe up" or close the app after leaving and before re-joining a new community.

@siepra will add notes about what he's found so far.

@holmesworcester holmesworcester moved this from Waiting for review to Next Sprint in Quiet Jan 2, 2024
@siepra
Copy link
Contributor

siepra commented Jan 3, 2024

My observation is, once left the community state-manager root saga is being forked multiple times:

 LOG  Leaving community
 LOG  closing socket connection
 LOG  canceling root task
 INFO  Clearing redux store
 LOG  websocket connected
 LOG  WEBSOCKET Forking state-manager sagas {"@@redux-saga/TASK": true, "cancel": [Function cancel], "cont": [Function anonymous], "context": {}, "end": [Function end], "error": [Function error], "id": 8699, "isAborted": [Function isAborted], "isCancelled": [Function isCancelled], "isRoot": undefined, "isRunning": [Function isRunning], "joiners": [], "meta": {"location": undefined, "name": "useIO"}, "queue": {"abort": [Function abort], "addTask": [Function addTask], "cancelAll": [Function cancelAll], "getTasks": [Function getTasks]}, "result": [Function result], "setContext": [Function setContext], "toPromise": [Function toPromise]}
 INFO  Flushing redux store
 INFO  Flushing redux store
 INFO  Flushing redux store
 INFO  Flushing redux store
 LOG  closing socket connection
 LOG  canceling root task
 LOG  canceling root task
 LOG  INIT_NAVIGATION: Starting deep link flow.
 LOG  INIT_NAVIGATION: Waiting for websocket connection before proceeding with deep link flow.
 LOG  INIT_NAVIGATION: Waiting for websocket connection before proceeding with deep link flow.
 LOG  websocket connected
 LOG  WEBSOCKET Forking state-manager sagas {"@@redux-saga/TASK": true, "cancel": [Function cancel], "cont": [Function anonymous], "context": {}, "end": [Function end], "error": [Function error], "id": 8947, "isAborted": [Function isAborted], "isCancelled": [Function isCancelled], "isRoot": undefined, "isRunning": [Function isRunning], "joiners": [], "meta": {"location": undefined, "name": "useIO"}, "queue": {"abort": [Function abort], "addTask": [Function addTask], "cancelAll": [Function cancelAll], "getTasks": [Function getTasks]}, "result": [Function result], "setContext": [Function setContext], "toPromise": [Function toPromise]}
 LOG  INIT_NAVIGATION: Continuing on deep link flow.
 LOG  Stored invitation codes []
 LOG  Current invitation codes [{"onionAddress": "3onqrkijcdiesy6eemsbb52dsqenr3srrm6f6zek62zscog7zsq4c4id", "peerId": "QmPGNv63roaTE1vrKpG8kNoynk7YYWTKtXx3AeisHRzdno"}]
 LOG  Is invitation data valid true
 LOG  INIT_NAVIGATION: Proceeding with connection to the community.
 LOG  INIT_NAVIGATION: Switching to the join community screen.
 LOG  create network saga
 LOG  create network saga: saving PSK
 LOG  INIT_NAVIGATION: Continuing on deep link flow.
 LOG  Stored invitation codes [{"onionAddress": "3onqrkijcdiesy6eemsbb52dsqenr3srrm6f6zek62zscog7zsq4c4id", "peerId": "QmPGNv63roaTE1vrKpG8kNoynk7YYWTKtXx3AeisHRzdno"}]
 LOG  Current invitation codes [{"onionAddress": "3onqrkijcdiesy6eemsbb52dsqenr3srrm6f6zek62zscog7zsq4c4id", "peerId": "QmPGNv63roaTE1vrKpG8kNoynk7YYWTKtXx3AeisHRzdno"}]
 LOG  Is invitation data valid true
 LOG  INIT_NAVIGATION: Proceeding with connection to the community.
 LOG  INIT_NAVIGATION: Switching to the join community screen.
 LOG  create network saga
 LOG  create network saga: saving PSK
 LOG  INIT_NAVIGATION: Switching to the username registration screen.
 LOG  INIT_NAVIGATION: Switching to the username registration screen.
 LOG  WEBSOCKET Entered start connection saga true
 LOG  WEBSOCKET Entered start connection saga true
 LOG  WEBSOCKET Entered start connection saga true
 LOG  WEBSOCKET Entered start connection saga true
 LOG  websocket connected
 LOG  websocket connected
 LOG  websocket connected
 LOG  WEBSOCKET Forking state-manager sagas {"@@redux-saga/TASK": true, "cancel": [Function cancel], "cont": [Function anonymous], "context": {}, "end": [Function end], "error": [Function error], "id": 9243, "isAborted": [Function isAborted], "isCancelled": [Function isCancelled], "isRoot": undefined, "isRunning": [Function isRunning], "joiners": [], "meta": {"location": undefined, "name": "useIO"}, "queue": {"abort": [Function abort], "addTask": [Function addTask], "cancelAll": [Function cancelAll], "getTasks": [Function getTasks]}, "result": [Function result], "setContext": [Function setContext], "toPromise": [Function toPromise]}
 LOG  WEBSOCKET Forking state-manager sagas {"@@redux-saga/TASK": true, "cancel": [Function cancel], "cont": [Function anonymous], "context": {}, "end": [Function end], "error": [Function error], "id": 9425, "isAborted": [Function isAborted], "isCancelled": [Function isCancelled], "isRoot": undefined, "isRunning": [Function isRunning], "joiners": [], "meta": {"location": undefined, "name": "useIO"}, "queue": {"abort": [Function abort], "addTask": [Function addTask], "cancelAll": [Function cancelAll], "getTasks": [Function getTasks]}, "result": [Function result], "setContext": [Function setContext], "toPromise": [Function toPromise]}
 LOG  websocket connected
 LOG  WEBSOCKET Forking state-manager sagas {"@@redux-saga/TASK": true, "cancel": [Function cancel], "cont": [Function anonymous], "context": {}, "end": [Function end], "error": [Function error], "id": 9613, "isAborted": [Function isAborted], "isCancelled": [Function isCancelled], "isRoot": undefined, "isRunning": [Function isRunning], "joiners": [], "meta": {"location": undefined, "name": "useIO"}, "queue": {"abort": [Function abort], "addTask": [Function addTask], "cancelAll": [Function cancelAll], "getTasks": [Function getTasks]}, "result": [Function result], "setContext": [Function setContext], "toPromise": [Function toPromise]}
 LOG  WEBSOCKET Forking state-manager sagas {"@@redux-saga/TASK": true, "cancel": [Function cancel], "cont": [Function anonymous], "context": {}, "end": [Function end], "error": [Function error], "id": 9795, "isAborted": [Function isAborted], "isCancelled": [Function isCancelled], "isRoot": undefined, "isRunning": [Function isRunning], "joiners": [], "meta": {"location": undefined, "name": "useIO"}, "queue": {"abort": [Function abort], "addTask": [Function addTask], "cancelAll": [Function cancelAll], "getTasks": [Function getTasks]}, "result": [Function result], "setContext": [Function setContext], "toPromise": [Function toPromise]}

It's as though multiple apps were running concurrently, sharing the same UI

@siepra siepra removed the 2.1.x label Jan 11, 2024
@siepra siepra moved this from Next Sprint to (Mobile) Ready for QA in Quiet Jan 11, 2024
@siepra siepra moved this from (Mobile) Ready for QA to Sprint in Quiet Jan 11, 2024
@siepra siepra moved this from Sprint to Next Sprint in Quiet Jan 11, 2024
@siepra siepra moved this from Sprint to In progress in Quiet Jan 25, 2024
@siepra
Copy link
Contributor

siepra commented Jan 25, 2024

I observed web socket client connecting more than once.

I think it has something to do with connection-manager's closeAllServices method, especially this part:

    if (this.serverIoProvider?.io) {
      this.logger('Closing socket server')
      this.serverIoProvider.io.close()
    }

The issue appears on both platforms so I assume the problem is not related to lifecycle changes, yet Kinga first observed it on iOS which directly calls closeAllServices when moving to background.

It's easiest to reproduce when combined with leaving the community. It executes leaveCommunity method that nests closeAllServices.

It looks like even though it closed socket server, it reconnects the old client's socket under certain conditions (which I'm trying to figure out). Is that even possible? @EmiM

There's a quicker way to observe this behaviour on iOS (although it probably won't break anything but it'll show results in logs):

  1. Open the app
  2. Minimise it
  3. Use a joining link

Here are shorten logs I got during debugging

[javascript] 'client: Websocket connected', '-CuTj0qrm_AgFfubAAAt'
[...]
[javascript] 'client: Closing socket connection', '-CuTj0qrm_AgFfubAAAt'
[...]
[javascript] INIT_NAVIGATION: Starting deep link flow.
[javascript] INIT_NAVIGATION: Waiting for websocket connection before proceeding with deep link flow.
[javascript] 'client: Websocket connected', 'O62kaWdiNaPE0RLTAAAv'
[...]
[javascript] NATIVE MODULES: Starting websocket connection
[javascript] WEBSOCKET: startConnectionSaga
[javascript] 'client: Websocket connected', 'F0E9wZtQOog1ZOlRAAAx'

Here's a branch containing additional loggings #2154

@siepra siepra moved this from In progress to Waiting for review in Quiet Jan 29, 2024
@siepra siepra moved this from Waiting for review to In progress in Quiet Jan 29, 2024
@siepra siepra changed the title Problems with re-joining community mobile Multi forking root saga Jan 29, 2024
@siepra
Copy link
Contributor

siepra commented Jan 29, 2024

Details moved to #2253

@siepra siepra removed this from Quiet Jan 29, 2024
siepra added a commit that referenced this issue Jan 30, 2024
* fix: mark redux store ready after leaving community #1970

* test: fix deepLink tests

* chore: fix lint

* chore: cleanup

* chore: update CHANGELOG.md

* chore: add debugging logs

* fix: reset deep link flag

* chore: cleanup iOS

* fix: correct redux cleanup order

* chore: comment out persistor flushing

* chore: add debug log for launching application

* chore: log socket id on its lifecycle callbacks

* fix: deep link redirection

* fix: undo comment out persistor cleanup

* fix: tests

* fix: lint

* chore: undo CHANGELOG.md changes

* chore: update CHANGELOG.md

* chore: cleanup

* chore: cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mobile
Projects
None yet
Development

No branches or pull requests

3 participants