Comments (7)
Ah just read a little more and I see where it is required to be an integer.
"If previous handle was provided, let handle be previous handle; otherwise, let handle be a user-agent-defined integer that is greater than zero that will identify the timeout to be set by this call in the list of active timers."
I'm happy to go make this argument with Jest
from node-proper-lockfile.
Looking at the code, the error you reported shouldn’t be happening as setTimeout should always return something. In case of the browser, it returns a integer, while in node it returns a time ref. It seems to me that your test environment is somehow mocking setTimeout in a bad way and returning nullish, causing the issue.
Are you using any lib to mock timers?
from node-proper-lockfile.
Thanks for getting back @satazor
Looks like jest is doing something funky with setTimeout
.
I've attemped using jest.useFakeTimers()
but it looks like the mock timers don't solve the issue.
I was able to confirm that creating a manual mock of setTimeout
which returns an empty object fixes the unref
of undefined issue.
It'll take further digging to figure out exactly what jest
is doing that is causing issues with setTimeout
from node-proper-lockfile.
I'm doing the same, and seeing the same error.
The PR that @mboperator submitted (#91) mitigates the issue in my case.
Given the fact that it's necessary to be defensive here for cases where setTimeout
returns something specifically different (an integer), it seems reasonable to me to be generally defensive against cases where it might return something else (like in this case undefined
).
The current implementation is defensive against everything that happens to be truthy but doesn't implement unref
. Why not go all the way and defend against nullish values as well?
from node-proper-lockfile.
I understand that the overall issue caused a lot of frustration. If the check was in place, you wouldn’t experience this issue at all, which at first might be a good thing. But if you think about it, it would be hiding a flaw from somewhere else that would eventually bite you in the future.
The spec says that setTimeout must return a handle that can be passed to clearTimeout, see https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
Since this is a bug with the environment you are running tests and not this lib, it seems unreasonable to implement a fix/check here.
from node-proper-lockfile.
Forgive me, I'm pretty new to reading specs like this, but it looks to me like undefined
can be passed to clearTimeout
.
If it really is against the spec to return undefined
from setTimeout I'm 100% with you, however I don't see in the spec you linked that this is quite the case.
"The clearTimeout() and clearInterval() methods must clear the entry identified as handle from the list of active timers of the WindowOrWorkerGlobalScope object on which the method was invoked, if any, where handle is the argument passed to the method. (If handle does not identify an entry in the list of active timers of the WindowOrWorkerGlobalScope object on which the method was invoked, the method does nothing.)"
-https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
clearTimeout
seems to be designed to accept arguments that don't identify handles and that this would include nullish values like undefined
which to me seems reasonable for situations like unit testing.
from node-proper-lockfile.
This is an old issue i'm going to close this! Feel free to reopen if it needs more discussion.
Thank you.
from node-proper-lockfile.
Related Issues (20)
- macOS: Error: ENOENT: no such file or directory, lstat '/private/tmp/ ... HOT 1
- Race condition in `mtime-precision/probe` HOT 4
- Feature Request: Provide an API to react on a stale lock that is reclaimed HOT 2
- Possibility to pass the lock to another process
- Impossible to compose a lock..
- Cannot kill debug client HOT 1
- bug: Ctrl-C doesn't work if just requiring proper-lockfile
- Cannot read property 'updateTimeout' of undefined HOT 1
- The lib doesn't work as expected, or I don't understand it's purpose HOT 1
- It doesn't work in Windows, or I don't understand it's logic HOT 1
- Follow up on the mtime check precision HOT 1
- (docs) missing information about throwing errors
- compromised lock throws error when release is called HOT 2
- Difference between lock.mtime and stat.mtime precision HOT 14
- electron app seems break HOT 3
- Electron start with an error alert relate this package. HOT 5
- Error: Lock file is already being held HOT 3
- Cannot read property 'updateTimeout' of undefined HOT 1
- Throws error if path leading to a file doesn't exist yet. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-proper-lockfile.