Skip to content

unref'd timers running in beforeExit time #1264

@brycebaril

Description

@brycebaril

When working out this test case for #1152 I came up with this:

var assert = require("assert") var intervals = 0 var i = setInterval(function () { intervals++ i.unref() eatTime() }, 10) function eatTime() { // the goal of this function is to take longer than 10ms, i.e. longer than the interval var count = 0 while (count++ < 1e7) { Math.random() } } process.on("exit", function () { assert.equal(intervals, 1) })

Note -- this requires the patch in #1152 to even terminate, or running Node.js 0.12+ which already has that fix.

I think what happens here is the blocking time causes the repeat time to trigger and the unreferenced timer gets executed in the beforeExit timeframe (nodejs/node-v0.x-archive@a2eeb43) when it shouldn't be. This can result in your application not terminating when it should, and functions that should not be executed being run.

This is a separate bug than #1151 (with fix #1152) and is not fixed by #1231

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