Page MenuHomePhabricator

[lib] Wait for tunnelbroker and keyserver connection when updating relationships
Needs RevisionPublic

Authored by angelika on Tue, Dec 17, 12:53 PM.
Tags
None
Referenced Files
F3511226: D14167.id46560.diff
Sat, Dec 21, 2:03 PM
Unknown Object (File)
Fri, Dec 20, 2:21 PM
Unknown Object (File)
Wed, Dec 18, 9:34 AM
Unknown Object (File)
Wed, Dec 18, 9:33 AM
Unknown Object (File)
Wed, Dec 18, 9:32 AM
Subscribers

Details

Reviewers
tomek
kamil
Summary

https://linear.app/comm/issue/ENG-9547/dms-created-when-ashoat-opened-web-app-after-not-touching-it-for-a

Implemented solution described by Ashoat here https://linear.app/comm/issue/ENG-9547/dms-created-when-ashoat-opened-web-app-after-not-touching-it-for-a#comment-5c104d82

waitForConnection is a bit ambiguous name but I couldn't think of a better one. waitForTunnelbrokerAndKeyserverConnection seems to long? I'm open to suggestions

Test Plan

Ideally it would be better to test it with Farcaster but I don't have Farcaster account so to simulate the issue:

  1. Have mobile and web clients that do not know each other
  2. Put a sleep() call before connecting to tunnelbroker socket (for example 20s)
  3. Close web client
  4. Send a DM on mobile to web. Make sure it's sent (checkmark)
  5. Open web client
  6. Quickly (before sleep from step 2 ends) add mobile to friends (with Settings -> friends -> add friends)

Before the changes the thread was duplicated
After the changes the app waits for tunnelbroker connection and only one thread is created

Diff Detail

Repository
rCOMM Comm
Branch
graszka22/ENG-9547
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

tomek requested changes to this revision.Fri, Dec 20, 4:06 AM

I have a couple of questions about this solution:

  1. Are we sure we want to wait for the connection in each place where useUpdateRelationships is used? There are a lot of them.
  2. Should we wait again after e.g. Tunnelbroker gets disconnected, or should we just wait for the initial connection?
  3. Do we want to have a timeout?
lib/hooks/wait-for-connection.js
17–39

This logic looks a bit broken to me:

  1. What if the waitForConnection function was called multiple times? We're resolving only the most recent promise because creating a new one results in overriding the ref.
  2. Is it guaranteed that if waitForConnection is called when isConnectedOrUnreachable is false, and then turns to true, the effect will always fire late enough so that the ref already contains the resolve function?
This revision now requires changes to proceed.Fri, Dec 20, 4:06 AM