Skip to content

Commit

Permalink
SDA-4182_racing: Add racing condition
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenTranHoangSym committed Jul 20, 2023
1 parent f9abb86 commit 65176f3
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/app/registry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ export const retrieveWindowsRegistry = async (): Promise<string> => {
const Registry = require('winreg');
const registryLocalStore = RegistryStore;
const fetchLogic = (err, channel) => {
if (err) {
if (err || !channel) {
logger.info('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 '';
}
}
};
Expand All @@ -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 channel;
}
return new Promise((resolve) => {
regKeyUser.get(CHANNEL_KEY, (error, channel) => {
if (error || !channel) {
logger.info('registry-handler: error occurred. Details: ', error);

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);
}
});
});
};

0 comments on commit 65176f3

Please sign in to comment.