diff --git a/app/index.ts b/app/index.ts index 246b40c6e..ebeadfbb2 100644 --- a/app/index.ts +++ b/app/index.ts @@ -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();