Merge pull request #1903 from NguyenTranHoangSym/SDA-4182_racing

SDA-4182_racing: Add racing condition
This commit is contained in:
NguyenTranHoangSym 2023-07-20 15:47:34 +07:00 committed by GitHub
commit f8ac374c54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,24 +12,22 @@ export const retrieveWindowsRegistry = async (): Promise<string> => {
const Registry = require('winreg');
const registryLocalStore = RegistryStore;
const fetchLogic = (err, channel) => {
if (err) {
logger.info('registry-handler: error occurred. Details: ', err);
if (err || !channel) {
logger.error('registry-handler: error occurred. Details: ', err);
return 'An error has occurred';
return '';
} else {
if (channel.type === RegistryValueType.REG_SZ) {
if (channel?.type === RegistryValueType.REG_SZ) {
registryLocalStore.setRegistry({ currentChannel: channel.value });
logger.info(
'registry-handler: value retrieved successfully, send to Registry Store',
);
return channel.value;
} else {
logger.info(
'registry-handler: the value was looked for did not exist or its VALUE_TYPE is incorrect',
);
return 'Key Value doesnt exist';
return '';
}
}
};
@ -44,18 +42,21 @@ export const retrieveWindowsRegistry = async (): Promise<string> => {
key: CHANNEL_NEST_LOCATION,
});
return regKeyUser.get(CHANNEL_KEY, (error, channel) => {
if (error && !channel) {
regKeyLocal.get(CHANNEL_KEY, (err, localChannel) => {
return fetchLogic(err, localChannel);
});
} else if (channel.type === RegistryValueType.REG_SZ) {
registryLocalStore.setRegistry({ currentChannel: channel.value });
logger.info(
'registry-handler: value retrieved successfully, send to Registry Store',
);
return new Promise((resolve) => {
regKeyUser.get(CHANNEL_KEY, (error, channel) => {
if (error || !channel) {
logger.error('registry-handler: error occurred. Details: ', error);
return channel;
}
regKeyLocal.get(CHANNEL_KEY, (err, localChannel) => {
resolve(fetchLogic(err, localChannel));
});
} else if (channel.type === RegistryValueType.REG_SZ) {
logger.info(
'registry-handler: value retrieved successfully, send to Registry Store',
);
registryLocalStore.setRegistry({ currentChannel: channel.value });
resolve(channel.value);
}
});
});
};