Iterate on client creation - #7591
Conversation
| clientEnterpriseHook(matrixClient) | ||
|
|
||
| newMatrixClientObservers.forEach { it.invoke(matrixClient) } | ||
| sessionStore.addSession(sessionData) |
There was a problem hiding this comment.
Worth noting that matrixClient.waitForKnownVerificationState() was not called in this case.
|
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #7591 +/- ##
===========================================
+ Coverage 80.98% 81.09% +0.10%
===========================================
Files 2781 2782 +1
Lines 81840 81844 +4
Branches 11252 11251 -1
===========================================
+ Hits 66280 66370 +90
+ Misses 11217 11120 -97
- Partials 4343 4354 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| suspend fun create( | ||
| client: Client, | ||
| sessionData: SessionData, | ||
| isMessageSearchAvailable: Boolean, | ||
| ): RustMatrixClient { |
There was a problem hiding this comment.
Note by doing this we're not reusing an already valid client and are forcing the creation of a different client, which can mean ~1s for opening the SDK DBs again I think. It's not that important since it happens on the login flow, but that's why we had 2 methods and tried to avoid destroying the current client in the log in flows.
There was a problem hiding this comment.
I see. So maybe we could have a second hook to update the client once it's logged in? Not sure if this will work for @richvdh .
To let this PR focused on this change, I'll extract the first commit to its own PR.
There was a problem hiding this comment.
I have measured 580ms spent on the new method finalizeClientCreation, but only 80 ms for the method restoreSession in it, so the impact is actually very small (?)
There was a problem hiding this comment.
In theory we could work around it, but for my usecase it would be much better to run the hook before the client is created. I don't need to know the userid though, so provided the hook actually gets called whenever a client is created, that would be fine.
There was a problem hiding this comment.
I do not understand, how the hook using MatrixClient can be called before MatrixClient is created? Are you talking about ClientEnterpriseHook or something else?
There was a problem hiding this comment.
I'm talking about ClientBuilderEnterpriseHook. I need a way to call methods on the underlying rust-side ClientBuilder each time we build a Client.
I could probably work around it by adding methods to the rust-side MatrixClient and calling them after the client is created, but I'd much prefer to avoid that.
8462298 to
e647698
Compare
|
|
||
| /** | ||
| * Customize the [MatrixClientBuilder] for enterprise features. | ||
| * This method is invoked when a new [MatrixClientBuilder] is created to build a client for a specific session. |
There was a problem hiding this comment.
would be good to be explicit if this is called as well as the other method, or instead of it.
(also imho the two implementations should have different names, since they serve somewhat different purposes, but ymmv)
There was a problem hiding this comment.
The documentation of the other method is explicit: "This method is invoked everytime a new [MatrixClientBuilder] is created.", but yes, I can be explicit here to.
Regarding the different name, I think the different signature is enough. Do you have a suggestion for a better name?
There was a problem hiding this comment.
personally I'd call them something like beforeClientCreation and beforeClientCreationWithSession. (h/t @andybalaam who helped me here)
(nb you don't actually have to "tweak" the client builder in the methods -- you could just use them as an informative hook and return the builder untweaked. Hence, it feels like beforeX is a better name.)
But I really don't mind, it's very much up to you!
…sion Since the login flows stopped handing their client over to RustMatrixClientFactory and let finalizeClientCreation() build a fresh one from the SessionData, two problems appeared. The client built by loginWithQrCode() was never owned by anyone: it is not assigned to currentClient, so clear() had nothing to close and the Rust Client stayed open for the whole app lifetime, holding the session stores of the freshly logged in account. It is now tracked in currentClient, and also disposed of when the QR login fails, which is safe because that flow always builds its own client. The client of the session was also built while the login client was still open. Both use the same session paths, so their state and crypto SQLite stores, and the search index when message search is enabled, were opened twice at the same time with no cross process lock to protect them. clear() now runs before the final client is created. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
sessionPaths keeps pointing at the directories of the account which has just been logged in, and it was never reset. Adding another account calls setHomeserver(), whose rotateSessionPath() starts by deleting the directories of the previous sessionPaths, so the file and cache directories of the first account were wiped. finalizeClientCreation() now forgets the session paths once the login succeeded. It is done there rather than in clear() on purpose: after a failed attempt the directories are orphaned and must still be deleted by the rotateSessionPath() of the next attempt. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
4553b2d to
a817b6f
Compare
|
ganfra
left a comment
There was a problem hiding this comment.
Ok for me like this. Have you tried using QRCode login? Is there some risks to lose data when closing the client quickly after login?
AFAICT we haven't started any sync or encryption task at that point, so I think it should be ok. |
Is there not any verification thing done automatically when doing QR code login? |
I have checked again the QrCode login flow and it works fine, the session is created and verified. |



Content
Make sure that a RustMatrixClient is always created the same way, either when restoring a session or when signing in.
It ensure that the hook are correctly applied.
(See #7590 (review)).
Motivation and context
Ensure that hook works the same way.
Screenshots / GIFs
Tests
Tested devices
Checklist