Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unref'ing the timer in some environments #40

Merged
merged 8 commits into from
Jan 15, 2020

Conversation

nodkz
Copy link
Contributor

@nodkz nodkz commented Dec 19, 2019

It very strange but in some cases thrown "Error: interval.unref is not a function" in 5.1.0.

Error is thrown in line 56:

get-port/index.js

Lines 50 to 57 in 0edd17a

if (interval === undefined) {
interval = setInterval(() => {
lockedPorts.old = lockedPorts.young;
lockedPorts.young = new Set();
}, releaseOldLockedPortsIntervalMs);
interval.unref();
}

If we change code to
if(interval.unref) interval.unref();

Then the error disappears.

It very strange but in some cases thrown "Error: interval.unref is not a function" in 5.1.0.

Error is thrown in line 56:

https://github.com/sindresorhus/get-port/blob/0edd17a5eb7ab8a02342c9defb0f622621a03e47/index.js#L50-L57

If we change code to
```if(interval.unref) interval.unref();```

Then the error disappears.
@nodkz
Copy link
Contributor Author

nodkz commented Dec 19, 2019

I found the root of the problem - it's Jest:
jestjs/jest#9033

It should be used with jest-environment-node and not the default jsdom env.

@sindresorhus
Copy link
Owner

You cannot assume the problem is Jest. Electron in render mode also doesn't have .unref. I think it would be best to just guard it without a message.

@nodkz
Copy link
Contributor Author

nodkz commented Dec 24, 2019

Agreed 👍

It's ready for squashing.

@sindresorhus sindresorhus changed the title fix: "Error: interval.unref is not a function" Fix unref'ing the timer in some environments Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants