Improve the handling of sync child jobs to ensure it behaves correctly
in all scenarios.
The sync service now uses a isolated context to avoid all the pipeline
stages shutting down before all the sync tasks have had the opportunity
to run their course.
The job waiter now immediately starts with a counter of 1 and waits
until all the child and the parent job finish before considering the
work to be finished.
Finally, we also handle the case where a sync job can't be queued
because the calling context has been cancelled.
When syncing an account, if the user creates a new address and then
changes it to be the default address in combined address mode we need
to update the connector maps so that the new primary address ID can be
found in that map.
Includes https://github.com/ProtonMail/go-proton-api/pull/130
Ensure that the heartbeat background task is stopped before we close
the users as it accesses data within these instances.
Additionally, we also make sure that when telemetry is disabled, we stop
the background task.
Finally, `HeartbeatManager` now specifies what the desired interval is
so we can better configure the test cases.
* Ensure IMAP service sync cancel request waits until the sync has
completely cancelled rather than just signaling. It's possible that
due the context reset on `group.Cancel` that something may have not
have been bookmarked correctly in subsequent sync restarts.
* Handle connection lost/restored events in the services. Removes the
need to lock bridge users. Which could conflict with other ongoing
lock operations. Additionally, it ensure that if one service is
blocked it doesn't block the entire bridge.
* Revise access to bridge user locks.
After we detect that the user has suffered the GODT-3003 bug due the
vault corruption not ensuring that a previous sync state would be
erased, we patch the gluon db directly and then reset the sync state.
After the account is added, the sync is automatically triggered and the
account state fixes itself.
Incoming messages which arrive into labels we know during sync are now
presented to the IMAP clients.
We also allow messages to be deleted while syncing if deleted on other
clients.
Other operations such as moving, marking messages as read and label
operations need to be considered in a follow up patch as they are far
more complex.
The IMAP service no longer blocks the event loop from progressing. When
syncing the event loop continues as usual, allow other parts of the
bridge to continue updating.
Once the sync is complete, it resets the event id back to the last
handled id before sync started and then we play catch up.