From 51d6ab01c98e9e73836e7117f949bfb7c1fdee9d Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Wed, 26 Jul 2017 20:59:01 -0300 Subject: [PATCH 1/2] Avoid an indefinite recursion that grows the call stack when reporting the current state fails We used to have a recursion based on Promises and Promise.delay, which caused the promise never to resolve so eventually the stack would be exhausted. This fixes it by using a simpler way to check if reporting the state is in progress and using a setImmediate to call applyState outside of the Promise chain. Change-Type: patch Signed-off-by: Pablo Carranza Velez --- src/device.coffee | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 From a3b5b0370bae69d74b5a31b704b3cb2d7f8ea4ff Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Fri, 3 Nov 2017 02:31:04 +0000 Subject: [PATCH 2/2] v6.4.2 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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",