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

Making IgnoredInvites mostly sync. #2653

Closed
wants to merge 6 commits into from

Conversation

Yoric
Copy link

@Yoric Yoric commented Sep 8, 2022

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.

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

This change is marked as an internal change (Task), so will not be included in the changelog.

Type: task

@Yoric Yoric requested a review from a team as a code owner September 8, 2022 08:38
@github-actions github-actions bot added the T-Task Tasks for the team like planning label Sep 8, 2022
src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
@Yoric Yoric force-pushed the yoric/ignore-invites-3847-2 branch from ff23480 to b8bb5d2 Compare September 15, 2022 15:53
@Yoric
Copy link
Author

Yoric commented Sep 23, 2022

@t3chguy Is this any better? The any code makes it clearer what data has been validated and what data hasn't.

@Yoric Yoric requested a review from t3chguy September 23, 2022 12:57
@t3chguy
Copy link
Member

t3chguy commented Sep 23, 2022

@Yoric sorry going to have to bump this back to the queue due to other obligations

@t3chguy t3chguy requested review from a team, germain-gg and turt2live and removed request for t3chguy and a team September 23, 2022 12:59
Copy link
Member

@turt2live turt2live left a 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.

src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
this.getOrCreateTargetRoomPromise = (async () => {
// We need to create our own policy room for ignoring invites.
target = (await this.client.createRoom({
name: "Individual Policy Room",
Copy link
Member

Choose a reason for hiding this comment

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

Should this be translated?

Copy link
Author

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?

try {
// Nobody is calling the method at the moment.
// Register ourselves as the leader and start creating our policy room.
this.getOrCreateTargetRoomPromise = (async () => {
Copy link
Member

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

Copy link
Author

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 {
Copy link
Member

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?

Copy link
Author

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} {
Copy link
Member

Choose a reason for hiding this comment

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

these also need types

Copy link
Author

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!

src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
src/models/invites-ignorer.ts Outdated Show resolved Hide resolved
Comment on lines +237 to +250
// Thanks to run-to-completion, the uninterruptible behavior of this
// method is the following:
Copy link
Member

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 :)

Copy link
Member

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?

Copy link
Author

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 :)

@germain-gg germain-gg removed their request for review September 30, 2022 08:20
@Yoric
Copy link
Author

Yoric commented Oct 21, 2022

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.

Well, I've been asked by my react-sdk reviewer to make things sync :)

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.

Should be matrix-org/matrix-spec-proposals#3847, iirc.

@Yoric Yoric requested review from t3chguy and turt2live October 31, 2022 08:36
Copy link
Member

@turt2live turt2live left a 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.

@Yoric
Copy link
Author

Yoric commented Nov 3, 2022

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:

  • This PR exists because @t3chguy requested that I make the code sync here. Should I change the commit message to clarify this?
  • I re-requested review because at least 3 conversations are waiting for a response on your part. I realize that I should have cleared up the resolved conversations, my bad.
  • Regarding the test failures, if someone could give me a hand understanding them, I would be grateful. All these test failures show up in code that, as far as I can tell, I haven't impacted, even from afar.

Yoric added 2 commits November 3, 2022 13:35
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.
@Yoric Yoric force-pushed the yoric/ignore-invites-3847-2 branch from 56dc713 to 46de018 Compare November 3, 2022 12:37
@t3chguy t3chguy removed their request for review April 27, 2023 10:12
@florianduros
Copy link
Contributor

Hi!

The PR is 2 years old and stuck.
I'm closing it. Feel free to reopen it if you want to continue to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants