Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Artificial _called property set on Timeout instance... #248

Merged
merged 4 commits into from
Dec 1, 2017

Conversation

ilguzin
Copy link

@ilguzin ilguzin commented Nov 24, 2017

... to have Timeout.isRunning() work properly for legacy node.js versions. Resolves mongodb-js/mongodb-core#247.

Fixing Timeout.isRunning was probably the best way to solve the issue and fit into the initial idea behind Timeout class.

Also returned back 0.10 and 0.12 targets for Travis. For that reason the 'request' lib has been fixed to @2.65.0 version in dev deps and added tests for the memory leak issue.

It does not seem to be reasonable to have these legacy targets to be turned off simply because of Hawk semver. That move has eventually played a dramatic role in hidding of the Timeout._called absence for v0.12 which was causing memory leak.

@ilguzin ilguzin changed the title Fixed artificial _called property set on Timeout instance to have Tim… Artificial _called property set on Timeout instance... Nov 28, 2017
@mbroadst mbroadst requested a review from daprahamian December 1, 2017 19:53
@mbroadst
Copy link
Member

mbroadst commented Dec 1, 2017

@daprahamian please take a look at this

@@ -217,7 +217,8 @@ function Timeout(fn, time) {

this.start = function () {
if (!this.isRunning()) {
timer = setTimeout(fn, time);
// The artificial _called is set here for compatibility with node.js 0.10.x/0.12.x versions
timer = setTimeout(function() { fn(); if (timer !== false && timer._called === undefined) { timer._called = true; } }, time);
Copy link
Contributor

@daprahamian daprahamian Dec 1, 2017

Choose a reason for hiding this comment

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

Can you please incorporate the following changes:

  1. replace timer !== false with just timer
  2. Break this all out into multiple lines.

Ideally, it would be something like this?

timer = setTimeout(function() {
  fn();
  if (timer && timer._called === undefined) {
    timer._called = true;
  }
}, time);

Copy link
Contributor

@daprahamian daprahamian left a comment

Choose a reason for hiding this comment

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

Please address the previous comment

@ilguzin
Copy link
Author

ilguzin commented Dec 1, 2017

Any chance to see it in next release this month?

@mbroadst
Copy link
Member

mbroadst commented Dec 1, 2017

@ilguzin there will be a 2.x release next week

@mbroadst mbroadst requested review from mbroadst and jlord December 1, 2017 21:00
@ilguzin
Copy link
Author

ilguzin commented Dec 1, 2017

@mbroadst, cool! Thanks :-)

@daprahamian daprahamian merged commit c7c72b2 into mongodb-js:2.0 Dec 1, 2017
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.

3 participants