Skip to content

Timer's unref unreliable when http module required after using them #1151

@brycebaril

Description

@brycebaril

Finally narrowed this down to a (admittedly bizarre) test case -- still looking into exactly why it happens -- but generally there appears to be a race condition or off-by-one in the timer unref management if the unref is called and then later the http module is required:

setImmediate(function () {
  require("http")
})

var i = setInterval(function () {
  setImmediate(process.exit)
}, 10)
i.unref()

process.on("exit", logstuff)

function logstuff() {
  console.log(process._getActiveHandles())
}

With 0.10 or 0.12 this logs [] which is expected because the interval was unreferenced.

In io.js you get:

[ { '0': [Function: listOnTimeout],
    _idleNext: 
     { _idleTimeout: 10,
       _idlePrev: [Circular],
       _idleNext: [Circular],
       _idleStart: 1218064360,
       _onTimeout: [Function: wrapper],
       _repeat: true,
       _handle: [Object] },
    _idlePrev: 
     { _idleTimeout: 10,
       _idlePrev: [Circular],
       _idleNext: [Circular],
       _idleStart: 1218064360,
       _onTimeout: [Function: wrapper],
       _repeat: true,
       _handle: [Object] },
    msecs: 10 } ]

Which is showing the unreferenced timer.

I found this when my application was supposed to be shutting down but was being kept alive by an unreferenced setInterval timer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions