Merge pull request #3147 from Bilb/fix-restore-push-too-soon

fix: postpone first sync after start
pull/3142/head
Audric Ackermann 1 year ago committed by GitHub
commit db1a1efa32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -184,6 +184,7 @@ label {
box-shadow: var(--modal-drop-shadow); box-shadow: var(--modal-drop-shadow);
overflow: hidden; overflow: hidden;
overflow-y: auto;
display: flex; display: flex;
flex-direction: column; flex-direction: column;

@ -306,8 +306,12 @@ async function shouldDropIncomingPrivateMessage(
envelope: EnvelopePlus, envelope: EnvelopePlus,
content: SignalService.Content content: SignalService.Content
) { ) {
const isUs = UserUtils.isUsFromCache(envelope.source);
// sentAtMoreRecentThanWrapper is going to be true, if the latest contact wrapper we processed was roughly more recent that this message timestamp // sentAtMoreRecentThanWrapper is going to be true, if the latest contact wrapper we processed was roughly more recent that this message timestamp
const moreRecentOrNah = await sentAtMoreRecentThanWrapper(sentAtTimestamp, 'ContactsConfig'); const moreRecentOrNah = await sentAtMoreRecentThanWrapper(
sentAtTimestamp,
isUs ? 'UserConfig' : 'ContactsConfig'
);
const isSyncedMessage = isUsFromCache(envelope.source); const isSyncedMessage = isUsFromCache(envelope.source);
if (moreRecentOrNah === 'wrapper_more_recent') { if (moreRecentOrNah === 'wrapper_more_recent') {
@ -319,10 +323,28 @@ async function shouldDropIncomingPrivateMessage(
? content.dataMessage?.syncTarget || undefined ? content.dataMessage?.syncTarget || undefined
: envelope.source; : envelope.source;
// handle the `us` case first, as we will never find ourselves in the contacts wrapper. The NTS details are in the UserProfile wrapper.
if (isUs) {
const us = getConversationController().get(envelope.source);
const ourPriority = us?.get('priority') || CONVERSATION_PRIORITIES.default;
if (us && ourPriority <= CONVERSATION_PRIORITIES.hidden) {
// if the wrapper data is more recent than this message and the NTS conversation is hidden, just drop this incoming message to avoid showing the NTS conversation again.
window.log.info(
`shouldDropIncomingPrivateMessage: received message in NTS which appears to be hidden in our most recent libsession userconfig, sentAt: ${sentAtTimestamp}. Dropping it`
);
return true;
}
window.log.info(
`shouldDropIncomingPrivateMessage: received message on conversation ${syncTargetOrSource} which appears to NOT be hidden/removed in our most recent libsession userconfig, sentAt: ${sentAtTimestamp}. `
);
return false;
}
if (!syncTargetOrSource) { if (!syncTargetOrSource) {
return false; return false;
} }
if (syncTargetOrSource.startsWith('05')) {
const privateConvoInWrapper = await ContactsWrapperActions.get(syncTargetOrSource); const privateConvoInWrapper = await ContactsWrapperActions.get(syncTargetOrSource);
if ( if (
!privateConvoInWrapper || !privateConvoInWrapper ||
@ -330,20 +352,22 @@ async function shouldDropIncomingPrivateMessage(
) { ) {
// the wrapper is more recent that this message and there is no such private conversation. Just drop this incoming message. // the wrapper is more recent that this message and there is no such private conversation. Just drop this incoming message.
window.log.info( window.log.info(
`received message on conversation ${syncTargetOrSource} which appears to be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. Dropping it` `shouldDropIncomingPrivateMessage: received message on conversation ${syncTargetOrSource} which appears to be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. Dropping it`
); );
return true; return true;
} }
window.log.info( window.log.info(
`received message on conversation ${syncTargetOrSource} which appears to NOT be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. ` `shouldDropIncomingPrivateMessage: received message on conversation ${syncTargetOrSource} which appears to NOT be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. `
); );
} catch (e) { } else {
window.log.warn( window.log.info(
'ContactsWrapperActions.get in handleSwarmDataMessage failed with', `shouldDropIncomingPrivateMessage: received message on conversation ${syncTargetOrSource} but neither NTS not 05. Probably nothing to do but let it through. `
e.message
); );
} }
} catch (e) {
window.log.warn('shouldDropIncomingPrivateMessage: failed with', e.message);
}
} }
return false; return false;
} }

@ -21,6 +21,7 @@ import {
PersistedJob, PersistedJob,
RunJobResult, RunJobResult,
} from '../PersistedJob'; } from '../PersistedJob';
import { DURATION } from '../../../constants';
const defaultMsBetweenRetries = 15000; // a long time between retries, to avoid running multiple jobs at the same time, when one was postponed at the same time as one already planned (5s) const defaultMsBetweenRetries = 15000; // a long time between retries, to avoid running multiple jobs at the same time, when one was postponed at the same time as one already planned (5s)
const defaultMaxAttempts = 2; const defaultMaxAttempts = 2;
@ -55,6 +56,8 @@ async function retrieveSingleDestinationChanges(
return { messages: outgoingConfResults, allOldHashes: compactedHashes }; return { messages: outgoingConfResults, allOldHashes: compactedHashes };
} }
let firstJobStart: number | undefined;
/** /**
* This function is run once we get the results from the multiple batch-send. * This function is run once we get the results from the multiple batch-send.
*/ */
@ -191,6 +194,18 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
return RunJobResult.Success; return RunJobResult.Success;
} }
const singleDestChanges = await retrieveSingleDestinationChanges(thisJobDestination); const singleDestChanges = await retrieveSingleDestinationChanges(thisJobDestination);
if (!firstJobStart) {
firstJobStart = Date.now();
}
// not ideal, but we need to postpone the first sync job to after we've handled the incoming config messages
// otherwise we are pushing an incomplete config to the network, which will need to be merged and that action alone
// will bump the timestamp of the config.
// We rely on the timestamp of configs to know when to drop messages that would unhide/unremove a conversation.
// The whole thing is a dirty fix of a dirty fix, that will **eventually** need proper fixing
if (Date.now() - firstJobStart <= 20 * DURATION.SECONDS) {
return RunJobResult.RetryJobIfPossible;
}
// If there are no pending changes then the job can just complete (next time something // If there are no pending changes then the job can just complete (next time something
// is updated we want to try and run immediately so don't scuedule another run in this case) // is updated we want to try and run immediately so don't scuedule another run in this case)

Loading…
Cancel
Save