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

fix: Emit WebxdcInstanceDeleted events when deleting a chat (#6670) #6718

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iequidoo
Copy link
Collaborator

@iequidoo iequidoo commented Mar 30, 2025

Not sure that emitting events optimistically is a good solution, but emitting them after the transaction (as we do everywhere) is also not reliable if the program crashes before that. It seems that the only proper way is to introduce persistent events which are removed by the app from db after processing. Returning an indefinite number of MsgId-s from the transaction may eat up memory, but adding LIMIT to SELECT makes the fix just useless.

Fix #6670

@iequidoo iequidoo requested a review from Simon-Laux March 30, 2025 05:44
@Simon-Laux
Copy link
Contributor

Simon-Laux commented Mar 30, 2025

> is also not reliable if the program crashes before that.

do you mean the function "crashing"? if core crashes all events are lost anyway and on a restart it loads the most recent state, so not sure I understand the problem case you are describing.

nvm I forgot it is about one of the few events with side effects

To protect against crashes we could alternatively save a list of message ids to delete somewhere in the db and add an api to retrieve them on appstartup and when there are WebxdcInstanceDeleted events

@r10s
Copy link
Contributor

r10s commented Mar 30, 2025

To protect against crashes we could alternatively save a list of message ids to delete somewhere in the db and add an api to retrieve them on appstartup and when there are WebxdcInstanceDeleted events

i do not think, that effort is needed in practise.

when the app crashes the webxdc window etc is usually also removed. might be cornercases left for notifications or icons not being removed, but that alone would not justify keeping events in database (i know, there is some incentive to do that for $reasons, but that is out of scope of this PR)

in general, it should not be the end of the world when an event is missing after program start

i think, it is no secret that i am sceptical about any event causing additional effort or database calls anyways :) EDIT: that's offtopic :)

@Simon-Laux
Copy link
Contributor

Simon-Laux commented Mar 30, 2025

deltachat desktop and deltachat tauri create and store different browser sessions/data directories for each account and on dc tauri even for each webxdc.

So loosing the event will mean there is a folder not cleaned up until you delete the account. (webxdc's data is still on file system)

@r10s I think mobile(iOS and android) just uses different origins for isolation. I don't know if mobile removes the data from a webxdc at all, after the message is deleted, so might not apply to mobile, yet.

@iequidoo iequidoo marked this pull request as draft March 30, 2025 22:03
@iequidoo iequidoo force-pushed the iequidoo/chat-delete-WebxdcInstanceDeleted branch from a552642 to f2c02d1 Compare March 30, 2025 22:27
@r10s
Copy link
Contributor

r10s commented Mar 30, 2025

well, data is deleted after 30 days or so. not sure about indexdb, which however is not used much in practise. compared to all the overhead, for now, we can ignore that issue

for desktop, it seems be easy enough to iterate over the dirs and delete the ones without a message. but also there, it seems fine to accept some overhead for now.

remember, we're talking about app crashes at exact time of delition, better spend time to fix crashes (have we seen any crash in that area?)

@Simon-Laux
Copy link
Contributor

Simon-Laux commented Mar 30, 2025

well, data is deleted after 30 days or so

where do you get that number from?

have we seen any crash in that area?

not that I know of, it seems to be theoretical. seems like @iequidoo brought it up as potential issue.
I agree that we should ignore the theoretical crash issue for now

src/chat.rs Outdated
Comment on lines 798 to 799
// Let's emit events optimistically and not return webxdc `MsgId`s from the
// transaction to not add LIMIT to SELECT above.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the comment. what is the meaning of it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to improve the comment. I just don't want to allocate a vector of unlimited size

assert_eq!(msg_id, instance.id);
Ok(())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

would make sense to also make a test that checks that WebxdcInstanceDeleted is only emitted for deleted webxdc messages and one that makes sure only that it only emits the events from the chat where the message was deleted from.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I extended the test, now it creates two chats with webxdc messages and also sends a text message to the chat aimed for deletion

@iequidoo
Copy link
Collaborator Author

So loosing the event will mean there is a folder not cleaned up until you delete the account. (webxdc's data is still on file system)

If so, i think that the app should first list webxdc messages in the chat, then delete all associated data, then messages themselves (all this can be done in several iterations if there are many webxdc messages) and only then delete the chat itself, i.e. the app shouldn't rely on events (which still can be emitted at least for feature-completeness). If mobile apps don't need to clean up anything additionally, they can just delete a chat as currently.

@Simon-Laux
Copy link
Contributor

Simon-Laux commented Mar 31, 2025

don't forget that message deletion is synced between devices, we still need the event.

@iequidoo iequidoo force-pushed the iequidoo/chat-delete-WebxdcInstanceDeleted branch from f2c02d1 to 90a840b Compare March 31, 2025 01:19
@iequidoo iequidoo marked this pull request as ready for review March 31, 2025 01:22
@iequidoo
Copy link
Collaborator Author

don't forget that message deletion is synced between devices, we still need the event.

True, so we anyway need to add some kind of persistent events to make webxdcs deletion reliable at least for Desktop. There are other ways in which messages may be deleted, e.g. delete_device_after may be set. Let's not fix this for now

@iequidoo iequidoo requested a review from Simon-Laux March 31, 2025 01:26
@r10s
Copy link
Contributor

r10s commented Mar 31, 2025

well, data is deleted after 30 days or so

where do you get that number from?

some ppl were complaining that eg, wonster stats are gone after not opening the app some time :)

afaik, there is no "hard timelimit", though. but on "storage pressure" browser/webview seem to clean up

we discussed that several times, agreeing that for now, it is fine. eg. spending our resources into deduplication probably saves 10-100 times more storage than thinking too much about localstorage/indexdb. the vast majority of cases is small data, if there is sth left, then it's that, at some point it will be cleaned 🤷‍♂️

and yes, i agree on ignoring the issue for now to not complicate things.

src/chat.rs Outdated
Comment on lines 798 to 800
// Let's emit events optimistically (before the transaction completes) and not
// return webxdc `MsgId`s from the transaction because otherwise we need a vector of
// indefinite size in memory.
Copy link
Contributor

@r10s r10s Mar 31, 2025

Choose a reason for hiding this comment

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

while probably okay to emit the events before, i do not agree with the reasoning that a "a vector of indefinite size in memory" is an issue here.

i have a huge account, and if it is much in the largest chat (testing!) maybe 500 webxdc. a vector of that size, and even if it is 500x more is not an issue at all.

Copy link
Collaborator Author

@iequidoo iequidoo Apr 1, 2025

Choose a reason for hiding this comment

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

I moved the code emitting events outside of the transaction and removed the comment. If the transaction becomes too huge, e.g. the chat contains too many messages, it doesn't scale well anyway and would block executing other transactions and the app, so let's not try to solve such problems in this PR

@iequidoo iequidoo force-pushed the iequidoo/chat-delete-WebxdcInstanceDeleted branch from 90a840b to 5a5f2c5 Compare April 1, 2025 01:43
@iequidoo iequidoo requested a review from r10s April 1, 2025 01:47
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.

WebxdcInstanceDeleted event is not emitted while deleting a chat
3 participants