diff --git a/CHANGELOG.md b/CHANGELOG.md index a89656d1..ced2beae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v6.4.2 - 2017-11-03 + +* Avoid an indefinite recursion that grows the call stack when reporting the current state fails #480 [Pablo Carranza Velez] + ## v6.4.1 - 2017-11-02 * Improve caching when building gosuper #520 [Pablo Carranza Velez] diff --git a/package.json b/package.json index dcc1658e..e6d2b9f2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "resin-supervisor", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", - "version": "6.4.1", + "version": "6.4.2", "license": "Apache-2.0", "repository": { "type": "git", diff --git a/src/device.coffee b/src/device.coffee index 3e75039e..5b8696c2 100644 --- a/src/device.coffee +++ b/src/device.coffee @@ -181,7 +181,7 @@ exports.getDeviceType = memoizePromise -> do -> APPLY_STATE_SUCCESS_DELAY = 1000 APPLY_STATE_RETRY_DELAY = 5000 - applyPromise = Promise.resolve() + applyPending = false targetState = {} actualState = {} updateState = { update_pending: false, update_failed: false, update_downloaded: false } @@ -193,8 +193,10 @@ do -> applyState = -> stateDiff = getStateDiff() if _.size(stateDiff) is 0 + applyPending = false return - applyPromise = Promise.join( + applyPending = true + Promise.join( utils.getConfig('apiKey') device.getID() (apiKey, deviceID) -> @@ -219,7 +221,7 @@ do -> Promise.delay(APPLY_STATE_RETRY_DELAY) .finally -> # Check if any more state diffs have appeared whilst we've been processing this update. - applyState() + setImmediate(applyState) exports.setUpdateState = (value) -> _.merge(updateState, value) @@ -238,7 +240,7 @@ do -> _.merge(targetState, updatedState) # Only trigger applying state if an apply isn't already in progress. - if !applyPromise.isPending() + if !applyPending applyState() return