Skip to content

Sync items are sometimes sent twice #5780

@link2xt

Description

@link2xt

send_sync_msg function generates a message with SystemMessage::MultiDeviceSync param. When such message is rendered, it gets part that consists of sync items that are currently in the multi_device_sync table and corresponding ids are saved into sync_ids_to_delete:
https://github.com/deltachat/deltachat-core-rust/blob/73f527e772b054946a652a774b03cdbf8744af03/src/mimefactory.rs#L1362-L1366
These sync_ids_to_delete are only deleted in create_send_msg_jobs here:
https://github.com/deltachat/deltachat-core-rust/blob/73f527e772b054946a652a774b03cdbf8744af03/src/chat.rs#L3001-L3005

It is possible that two SystemMessage::MultiDeviceSync messages are rendered at the same time if send_sync_msg is called from two threads at once.

When UI archives the message with set_visibility, a new sync message is created here:
https://github.com/deltachat/deltachat-core-rust/blob/73f527e772b054946a652a774b03cdbf8744af03/src/chat.rs#L691-L694
This results in calling add_sync_item which adds a new entry into multi_device_sync table, followed by calling send_sync_msg:
https://github.com/deltachat/deltachat-core-rust/blob/73f527e772b054946a652a774b03cdbf8744af03/src/chat.rs#L2239-L2245

At the same time SMTP loop may be interrupted and call send_sync_msg here from send_smtp_messages:
https://github.com/deltachat/deltachat-core-rust/blob/73f527e772b054946a652a774b03cdbf8744af03/src/smtp.rs#L671

This results in two send_sync_msg functions running in parallel, reading the same multi_device_sync entry from the table and then deleting the same entry twice. Two messages are rendered this way and get added to smtp table, then sent.

This problem resulted in flakyness of test_multidevice_sync_chat test here:
https://github.com/deltachat/deltachat-core-rust/blob/73f527e772b054946a652a774b03cdbf8744af03/deltachat-rpc-client/tests/test_chatlist_events.py#L200
Sometimes two identical sync messages about archiving the chat are sent. Second message generates duplicate event, so instead of archival, pinning and muting generating an event each more events are generated and 3 events are received when the chat is not yet muted.

This bug triggered flakiness in #5775, probably due to different timing than before.

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions