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

TypeError: setTimeout(...).unref is not a function #12

Open
akaRem opened this issue Oct 15, 2017 · 9 comments
Open

TypeError: setTimeout(...).unref is not a function #12

akaRem opened this issue Oct 15, 2017 · 9 comments

Comments

@akaRem
Copy link

akaRem commented Oct 15, 2017

Hi!
I have some problems with using stoppable on node v8.7.0

here are couple of stack traces:

    TypeError: setTimeout(...).unref is not a function

      at Immediate.setImmediate [as _onImmediate] (node_modules/stoppable/lib/stoppable.js:33:39)
      at runCallback (timers.js:785:20)
      at tryOnImmediate (timers.js:747:5)
      at processImmediate [as _immediateCallback] (timers.js:718:5)
    TypeError: setTimeout(...).unref is not a function

      at Immediate.setImmediate [as _onImmediate] (node_modules/stoppable/lib/stoppable.js:33:39)
      at runCallback (timers.js:785:20)
      at tryOnImmediate (timers.js:747:5)
      at processImmediate (timers.js:718:5)
      at _combinedTickCallback (internal/process/next_tick.js:131:7)
      at process._tickCallback (internal/process/next_tick.js:180:9)

I use babel, jest, flow and lots of other things, so it's hard to say is it problem of stoppable or not.

@thyb
Copy link

thyb commented Feb 28, 2018

setTimeout(destroyAll, grace).unref()

I had to remove .unref() at the end of the line and it now works for me in Electron v1.8.2

@ronkorving
Copy link

That's very strange, timer.unref() has existed since before Node 0.10: https://nodejs.org/api/timers.html#timers_timeout_unref

@boneskull
Copy link
Collaborator

It'd be cool to see what the exact setup is here, but the problem isn't stoppable's. stoppable could conceivably provide a workaround (e.g., using require('timer').setTimeout() instead), but I'd prefer not to make that change if it doesn't work.

@thyb If you're still encountering this, what happens when you restore unref() but instead change the line to require('timer').setTimeout(destroyall, grace).unref()?

@ronkorving
Copy link

I've seen things like this happen when run from Jest, which runs in Browser-mode by default, which means it replaces setTimeout and does not return an object with an unref function on it. Perhaps you're also running in some sort of browser emulation mode?

@glasser
Copy link

glasser commented Feb 23, 2021

Could the call to unref be replaced by a call to clearTimeout in the server.close callback?

The point of unref is that it lets the Node process terminate if it's the only remaining thing. But that process isn't going to terminate until the server is closed (unless you've also unreffed the server, I guess?), so the first time it could possibly be relevant is after the server.close callback is done. So we might as well just call clearTimeout ourselves at that point, no?

@antoc0d3
Copy link

replace setTimeout to setImmediate

@glasser
Copy link

glasser commented Mar 21, 2023

fwiw we ended up forking and making a ton of improvements to this nice class, now at https://github.com/apollographql/apollo-server/blob/main/packages/server/src/plugin/drainHttpServer/stoppable.ts

@boneskull
Copy link
Collaborator

@glasser Care to publish that module standalone?

@glasser
Copy link

glasser commented Mar 30, 2023

That hasn't been a priority for us --- I'd be happy to see somebody else copy it back from us and release and maintain it.

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

No branches or pull requests

6 participants