-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
Making IgnoredInvites mostly sync. #2653
Conversation
ff23480
to
b8bb5d2
Compare
@t3chguy Is this any better? The |
@Yoric sorry going to have to bump this back to the queue due to other obligations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I'm coming at this blind with no real idea what troubles you're facing on the react-sdk side: it may be worth a visit to Element Web Internal to talk about those challenges instead, as making things synchronous can be annoyingly more difficult than understanding the async code path.
This is also much harder to review because there's no MSC reference within the area of the diff - it's hard to see what the underlying data structures are without such a reference.
this.getOrCreateTargetRoomPromise = (async () => { | ||
// We need to create our own policy room for ignoring invites. | ||
target = (await this.client.createRoom({ | ||
name: "Individual Policy Room", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be translated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good point. Is there any way to do that in matrix-js-sdk? Or should I somehow pass that string from react-sdk?
src/models/invites-ignorer.ts
Outdated
try { | ||
// Nobody is calling the method at the moment. | ||
// Register ourselves as the leader and start creating our policy room. | ||
this.getOrCreateTargetRoomPromise = (async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically our pattern is = new Promise((resolve, reject) => { ... });
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With two calls to then
after the Promise
? Or is it an async
(resolve, reject) => { ... }
?
I've tried rewriting this call to use the Promise
constructor but it didn't really feel readable.
*/ | ||
private getIgnoreInvitesPolicies(): {[key: string]: any} { | ||
private getIgnoreInvitesPolicies(): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs a type - what is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs a type - what is it?
It's data coming from Matrix, therefore untrusted. Until I have checked it (which is what the caller functions do), I have no clue. The any
is there specifically to mark that it's untrusted. Is there a better way to write it down?
*/ | ||
private getPoliciesAndIgnoreInvitesPolicies(): | ||
{policies: {[key: string]: any}, ignoreInvitesPolicies: {[key: string]: any}} { | ||
{policies: any, ignoreInvitesPolicies: any} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these also need types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same response, sadly. If there is a better way to mark untrusted-deserialized-json than any
, I'll be happy to use it!
// Thanks to run-to-completion, the uninterruptible behavior of this | ||
// method is the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment (and the lines which follow) aren't really describing anything: it's just saying what we're about to do, not why it's important to have a lock. We know what it's about to do: there's code to tell us :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also describe why we don't need cross-client locking, considering this code is seemingly important.
It's further a bad smell that we need a lock at all - why would this code be called multiple times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment (and the lines which follow) aren't really describing anything: it's just saying what we're about to do, not why it's important to have a lock. We know what it's about to do: there's code to tell us :)
...because of race conditions? I'm reading, modifying, writing some user account data, that's inherently racy.
We should also describe why we don't need cross-client locking, considering this code is seemingly important.
Wait, we have cross-client locking? Where do I find the documentation on these?
It's further a bad smell that we need a lock at all - why would this code be called multiple times?
I come from a safety background. Any code is considered to be called multiple times unless proven otherwise :)
Well, I've been asked by my react-sdk reviewer to make things sync :)
Should be matrix-org/matrix-spec-proposals#3847, iirc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears to have failing checks, and it's still not really clear why this PR needs to exist. Usually we're heavily in support of async code, so I'm surprised we want to make it sync.
It's also hard to re-review this at the moment: all the conversations have been left unresolved, making it unclear which need further comment.
To clarify:
|
Experience and feedback from matrix-org/matrix-react-sdk#9255 indicates that we cannot integrate an async `IgnoredInvites.getRuleForInvite`. This PR: - rewrites `getRuleForInvite` to be sync; - adds some locking within `IgnoredInvites` to avoid race conditions noticed by @t3chguy.
56dc713
to
46de018
Compare
Hi! The PR is 2 years old and stuck. |
Experience and feedback from matrix-org/matrix-react-sdk#9255 indicates that we cannot integrate an async
IgnoredInvites.getRuleForInvite
. This PR:getRuleForInvite
to be sync;IgnoredInvites
to avoid race conditions noticed by @t3chguy.Checklist
This change is marked as an internal change (Task), so will not be included in the changelog.
Type: task