Skip to content

Expose arbitrary constants like TIMEOUT_MAX #11198

Description

@scottinet
  • Version: all
  • Platform: all
  • Subsystem: all

Hi!

Nothing urgent nor critical, but I came across the setTimeout delay limitation to 2^31-1, named TIMEOUT_MAX in timers.js
If I want to handle delays provided by clients potentially larger than that, I have to test it against what appears to be an arbitrary limitation. I have no problem with that. What bothers me is that I have no way to check if this limitation has changed when upgrading nodejs' version, except by hand, and only if I recall that I used it. I'm not really at ease with this. :-)
What would be handy in such cases is to expose this constant (and potentially others?), a bit like what's done in C with limits.h, so that we can use them without wondering if these are subject to future changes.

Activity

  1. claudiorodriguez commented on Feb 6, 2017

    @claudiorodriguez
    Contributor

    It's not really an arbitrary limitation - it's there because internally it's handled as a 32-bit integer. It doesn't come from node, it comes from v8 IIRC
    Does v8 expose these limits? It might not be possible to do what you propose if they're not part of v8's public API.

  2. mscdex commented on Feb 6, 2017

    @mscdex
    Contributor

    I don't believe this is related to V8 because timers are not defined by ES specs. The maximum value probably instead came from the HTML spec (which defines setTimeout() and the like) where the timeout value data type is listed as long, which is likely to be 32-bit (at least for historical reasons because setTimeout(), etc. existed before 64-bit computers became widespread, although some compilers on 64-bit still make long 32-bit).

    With that said, I'm not sure if there is any real benefit to exporting this maximum.

  3. added
    questionIssues asking questions about Node.js.
    timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().
    on Feb 6, 2017
  4. cjihrig commented on Feb 6, 2017

    @cjihrig
    Contributor

    I'm in favor of exposing this constant. Any module that deals with timeouts (especially long ones), needs to be aware of this value.

  5. bnoordhuis commented on Feb 6, 2017

    @bnoordhuis
    Member

    I don't believe this is related to V8 because timers are not defined by ES specs. The maximum value probably instead came from the HTML spec

    That's basically correct. I imposed the limit because browsers do.

    (Close to the truth. The real reason is because someone filed a bug report about it. I generally don't take action until forced to.)

  6. bnoordhuis commented on Feb 7, 2017

    @bnoordhuis
    Member

    After mulling it over I think I'm -0.5 on exposing the limit. Browsers don't either.

  7. scottinet commented on Feb 8, 2017

    @scottinet
    Author

    Instead of exposing this constant alone, which I agree is debatable because I do think that it won't fit in the current timer API, I was thinking more about exposing current system & nodejs limitations, such as the maximum number of arguments of a process, the maximum number of files a process can open, the maximum number of bytes in a filename (and in a path), and so on.

  8. bnoordhuis commented on Feb 8, 2017

    @bnoordhuis
    Member

    That may be more difficult to do accurately than you'd might think.

    • maximum number of arguments of a process - not always readily obtainable; on some platforms it's a function of the summed length of the arguments

    • maximum number of files a process can open - available through getrlimit(RLIMIT_NOFILE) but has no real Windows counterpart and on Unices you have that hard limit/soft limit dichotomy; which one do you pick?

    • the maximum number of bytes in a filename - depends on the file system; some file systems don't have hard limits, don't expose them or calculate them in characters, not bytes

    Consider that if it were easy to expose a particular system property in a cross-platform way, then node probably would have done it by now.

  9. Trott commented on Jul 26, 2017

    @Trott
    Member

    This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions