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

Protocol message to reset client state #1213

Conversation

magnetised
Copy link
Contributor

No description provided.

Copy link

linear bot commented Apr 30, 2024

@magnetised magnetised force-pushed the garry/vax-1817-protocol-message-to-reset-client-state branch 3 times, most recently from 46f0255 to 81369a3 Compare April 30, 2024 16:02
await this._resetClientState({
keepSubscribedShapes: true,
})
this._subscribePreviousShapeRequests()
Copy link
Member

Choose a reason for hiding this comment

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

Just an FYI: this working is contingent on the server behaviour. If the server does not remove client subscriptions from the ClientReconnectionInfo and from the WebsocketServer process' state, it will respond with errors to client's attempt to subscribe using a known subscription ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @alco, helpful reminder

@kevin-dp
Copy link
Contributor

kevin-dp commented May 1, 2024

I'm missing some context here but from @magnetised's explanation this morning, i'm guessing this message is meant to reset the client state when the client's permissions change, right? This is needed such that both the client and server are "in sync", i.e. they both restart from the "empty state" for this client (which i'm assuming is an enabling simplification). While this will also erase data that a client no longer has permission to see, this is not really it's primary purpose since we can't enforce that on malicious clients, right?

Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

Great work! I only left some minor comments.

this.emitter.on('command', callback)
}

unsubscribeToCommands(callback: CommandCallback): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we unsubscribe from something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed - I was just being consistent with the current unsubscribe function names e.g. unsubscribeToAdditionalData, unsubscribeToTransactions, unsubscribeToRelations

sql: 'SELECT * FROM main.parent',
})

t.deepEqual(results, [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also check that the subscribed shapes are kept?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. rather than crowbar it in here though, I'll add it in a later pr and ping you.

@magnetised
Copy link
Contributor Author

I'm missing some context here but from @magnetised's explanation this morning, i'm guessing this message is meant to reset the client state when the client's permissions change, right? This is needed such that both the client and server are "in sync", i.e. they both restart from the "empty state" for this client (which i'm assuming is an enabling simplification). While this will also erase data that a client no longer has permission to see, this is not really it's primary purpose since we can't enforce that on malicious clients, right?

that's right. pending a "proper" refresh of the subscription information after a permissions change, which is quite complex, this is a simple way to ensure that the client receives data consistent with their new permissions.

and no, we can't prevent people from seeing data that's on their device, even if they've lost permissions to see it, so the purpose of this re-sync is to maintain consistency between the client and the server

@magnetised magnetised force-pushed the garry/vax-1710-feature-flag-to-turn-on-permissions-in-hard-mode branch from 13c9458 to 7a2f4b9 Compare May 2, 2024 15:12
@magnetised magnetised force-pushed the garry/vax-1817-protocol-message-to-reset-client-state branch from 81369a3 to 5a7e0cc Compare May 2, 2024 15:13
Rather than attempt to reset the server connection's state after we've
asked the client to reset itself, we just close the connection. The
client will then re-connect automatically and, since it's had its state
reset, the server will treat it as a first connection (including
dropping all client reconnection state).

Since this is intended as an enabling simplification to maintain
consistency between client and server in the simplest way possible,
pending a more efficient, less brutal but much more complicated
solution, I've tried to keep the changes to the protocol as small as
possible.

Hence the use of `throw` -- it's either that or restructure all the
message handling on the server side to be more of a `reduce_while`
style.
@magnetised magnetised merged commit 4e9314a into garry/vax-1710-feature-flag-to-turn-on-permissions-in-hard-mode May 2, 2024
10 of 11 checks passed
@magnetised magnetised deleted the garry/vax-1817-protocol-message-to-reset-client-state branch May 2, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants