Fix an issue with reporting initial config using a stale target state

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-07-30 10:31:53 +01:00
parent 14b01b2009
commit ffe3da6261
2 changed files with 5 additions and 8 deletions

View File

@ -440,10 +440,9 @@ export class APIBinder {
);
}
const targetConfigUnformatted = _.get(
await TargetState.get(),
'local.config',
);
// We force a fresh get to make sure we have the latest state
// and can guarantee we don't clash with any already reported config
const targetConfigUnformatted = (await TargetState.get())?.local?.config;
if (targetConfigUnformatted == null) {
throw new InternalInconsistencyError(
'Attempt to report initial state with malformed target state',

View File

@ -164,12 +164,10 @@ const poll = async (
};
/**
* Get the latest target state, attempting a fetch first if we do not already have one
* Checks for target state changes and then returns the latest target state
*/
export const get = async (): Promise<TargetState> => {
if (cache == null) {
await update();
}
await update();
return _.cloneDeep(cache.body);
};