fix: make sure lastKnownKey is updated correctly

This commit is contained in:
Alexis
2021-09-15 16:03:14 +09:30
parent f72bcf7821
commit ea5bf9aeba

View File

@@ -120,9 +120,6 @@ am(async () => {
mothership.close();
coreLogger.debug('Disconnected from mothership\'s subscription endpoint.');
// Record last known key
lastKnownApiKey = newApiKey;
// Since we no longer have a key and
// everything is disconnected we can bail
if (newApiKey === undefined) {
@@ -130,8 +127,6 @@ am(async () => {
return;
}
apiManagerLogger.debug('Replacing my_servers key. Last known key was %s. New key is %s', lastKnownApiKey, newApiKey);
// We've never had a key before so let's start the internal API connection
// That'll then start the relay connection to mothership
if (!hasFirstKey && lastKnownApiKey === undefined) {
@@ -146,9 +141,17 @@ am(async () => {
// Mark this as being done
hasFirstKey = true;
// Record new key
apiManagerLogger.debug('Setting my_servers key. Key is "%s".', newApiKey);
lastKnownApiKey = newApiKey;
return;
}
// Record last known key
apiManagerLogger.debug('Replacing my_servers key. Last known key was "%s". New key is "%s".', lastKnownApiKey, newApiKey);
lastKnownApiKey = newApiKey;
// Stop internal connection
sockets.internal?.close();