Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Proper cancellation of status checks #189

Merged
merged 4 commits into from
Nov 15, 2017
Merged

Conversation

marcusoffesson
Copy link
Contributor

If a status check was canceled while it was running, it actually cancelled an old timeout identifier which in turn caused status check to go rouge (they continued forever, consuming memory in each iteration).

Any ideas of how to test this in a controlled environment is highly appreciated!

Copy link
Member

@wennmo wennmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

@peol peol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing—perhaps mock this.statusFetcher.fetch to resolve a promise after e.g. 5 seconds, and before that do stopStatusChecks() and ensure after 5 seconds that the loop is no longer running (by e.g. checking this.statusFetcher.fetch calls are still 1).

let health;
let metrics;

if (!this.running) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have this check on line 74 instead (e.g. only do another setTimeout if we are still running)—for clarity's sake.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move it, but be advised, it will lead to unnecessary health/metrics checks if cancellation is made in between status checks (which should be the normal scenario when we don't have recurring engine crashes).

Copy link
Contributor

@janmiderback janmiderback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 One comment on a convention.

@@ -70,18 +44,49 @@ class EngineEntry {
}

/**
* Periodical health and metrics checking.
*/
async checkStatus() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we moving away from the convention to have "private" methods not part of the class definition?
If so, we should align all code with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that's the reason!
Me and @peol discussed this and I did not know the reason for having it outside the class. Anyway, one argument for having it part of the class is to avoid having to use bind() which creates a new copy of the function every time it's called if I'm correctly informed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with putting them in the class def, but we should align.
Also, it would be very nice if we had some convention for naming "private" methods. I have seen _ suffix but our lint rules does not allow that, I think.

let health;
let metrics;

if (!this.running) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree 🙂

Copy link
Contributor

@peol peol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@janmiderback janmiderback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Only one comment

*/
async function checkStatus() {
let health;
let metrics;

if (!this.running) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - I know this is a matter of personal taste but I don't like early exits like this unless it is failure conditions.
I think is better to invert the logic and have if (this.running) { and then the code we want to run, avoiding multiple exit points if possible. Do as you please 🙂

@marcusoffesson marcusoffesson merged commit 5eef28b into master Nov 15, 2017
@marcusoffesson marcusoffesson deleted the mnf/fix-memory-leak branch November 15, 2017 15:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants