diff --git a/src/api-binder.ts b/src/api-binder.ts index cdedef99..ba10307f 100644 --- a/src/api-binder.ts +++ b/src/api-binder.ts @@ -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', diff --git a/src/device-state/target-state.ts b/src/device-state/target-state.ts index 0ad0f675..0abee584 100644 --- a/src/device-state/target-state.ts +++ b/src/device-state/target-state.ts @@ -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 => { - if (cache == null) { - await update(); - } + await update(); return _.cloneDeep(cache.body); };