mirror of https://github.com/lukechilds/node.git
Browse Source
`domain.dispose()` is generally considered an anti-pattern, has been
runtime-deprecated for over 4 years, and is a part of the `domain`
module that can not be emulated by `async_hooks`; so remove it.
Ref: https://nodejs.org/en/docs/guides/domain-postmortem/
Ref: 4a74fc9776
PR-URL: https://github.com/nodejs/node/pull/15412
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
canary-base
Anna Henningsen
7 years ago
committed by
Ruben Bridgewater
12 changed files with 17 additions and 336 deletions
@ -1,25 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const domain = require('domain'); |
|||
|
|||
// These were picked arbitrarily and are only used to trigger arync_hooks.
|
|||
const JSStream = process.binding('js_stream').JSStream; |
|||
const Socket = require('net').Socket; |
|||
|
|||
const handle = new JSStream(); |
|||
handle.domain = domain.create(); |
|||
handle.domain.dispose(); |
|||
|
|||
handle.close = () => {}; |
|||
handle.isAlive = () => { throw new Error(); }; |
|||
|
|||
const s = new Socket({ handle }); |
|||
|
|||
// When AsyncWrap::MakeCallback() returned an empty handle the
|
|||
// MaybeLocal::ToLocalChecked() call caused the process to abort. By returning
|
|||
// v8::Undefined() it allows the error to propagate to the 'error' event.
|
|||
s.on('error', common.mustCall((e) => { |
|||
assert.strictEqual(e.code, 'EINVAL'); |
|||
})); |
@ -1,97 +0,0 @@ |
|||
// Copyright Joyent, Inc. and other Node contributors.
|
|||
//
|
|||
// Permission is hereby granted, free of charge, to any person obtaining a
|
|||
// copy of this software and associated documentation files (the
|
|||
// "Software"), to deal in the Software without restriction, including
|
|||
// without limitation the rights to use, copy, modify, merge, publish,
|
|||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|||
// persons to whom the Software is furnished to do so, subject to the
|
|||
// following conditions:
|
|||
//
|
|||
// The above copyright notice and this permission notice shall be included
|
|||
// in all copies or substantial portions of the Software.
|
|||
//
|
|||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
|||
'use strict'; |
|||
|
|||
// This test makes sure that when a domain is disposed, timers that are
|
|||
// attached to that domain are not fired, but timers that are _not_ attached
|
|||
// to that domain, including those whose callbacks are called from within
|
|||
// the same invocation of listOnTimeout, _are_ called.
|
|||
|
|||
require('../common'); |
|||
const assert = require('assert'); |
|||
const domain = require('domain'); |
|||
let disposalFailed = false; |
|||
|
|||
// Repeatedly schedule a timer with a delay different than the timers attached
|
|||
// to a domain that will eventually be disposed to make sure that they are
|
|||
// called, regardless of what happens with those timers attached to domains
|
|||
// that will eventually be disposed.
|
|||
let a = 0; |
|||
log(); |
|||
function log() { |
|||
console.log(a++, process.domain); |
|||
if (a < 10) setTimeout(log, 20); |
|||
} |
|||
|
|||
let secondTimerRan = false; |
|||
|
|||
// Use the same timeout duration for both "firstTimer" and "secondTimer"
|
|||
// callbacks so that they are called during the same invocation of the
|
|||
// underlying native timer's callback (listOnTimeout in lib/timers.js).
|
|||
const TIMEOUT_DURATION = 50; |
|||
|
|||
setTimeout(function firstTimer() { |
|||
const d = domain.create(); |
|||
|
|||
d.on('error', function handleError(err) { |
|||
// Dispose the domain on purpose, so that we can test that nestedTimer
|
|||
// is not called since it's associated to this domain and a timer whose
|
|||
// domain is diposed should not run.
|
|||
d.dispose(); |
|||
console.error(err); |
|||
console.error('in domain error handler', |
|||
process.domain, process.domain === d); |
|||
}); |
|||
|
|||
d.run(function() { |
|||
// Create another nested timer that is by definition associated to the
|
|||
// domain "d". Because an error is thrown before the timer's callback
|
|||
// is called, and because the domain's error handler disposes the domain,
|
|||
// this timer's callback should never run.
|
|||
setTimeout(function nestedTimer() { |
|||
console.error('Nested timer should not run, because it is attached to ' + |
|||
'a domain that should be disposed.'); |
|||
disposalFailed = true; |
|||
process.exit(1); |
|||
}, 1); |
|||
|
|||
// Make V8 throw an unreferenced error. As a result, the domain's error
|
|||
// handler is called, which disposes the domain "d" and should prevent the
|
|||
// nested timer that is attached to it from running.
|
|||
err3(); // eslint-disable-line no-undef
|
|||
}); |
|||
}, TIMEOUT_DURATION); |
|||
|
|||
// This timer expires in the same invocation of listOnTimeout than firstTimer,
|
|||
// but because it's not attached to any domain, it must run regardless of
|
|||
// domain "d" being disposed.
|
|||
setTimeout(function secondTimer() { |
|||
console.log('In second timer'); |
|||
secondTimerRan = true; |
|||
}, TIMEOUT_DURATION); |
|||
|
|||
process.on('exit', function() { |
|||
assert.strictEqual(a, 10); |
|||
assert.strictEqual(disposalFailed, false); |
|||
assert(secondTimerRan); |
|||
console.log('ok'); |
|||
}); |
@ -1,62 +0,0 @@ |
|||
// Copyright Joyent, Inc. and other Node contributors.
|
|||
//
|
|||
// Permission is hereby granted, free of charge, to any person obtaining a
|
|||
// copy of this software and associated documentation files (the
|
|||
// "Software"), to deal in the Software without restriction, including
|
|||
// without limitation the rights to use, copy, modify, merge, publish,
|
|||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|||
// persons to whom the Software is furnished to do so, subject to the
|
|||
// following conditions:
|
|||
//
|
|||
// The above copyright notice and this permission notice shall be included
|
|||
// in all copies or substantial portions of the Software.
|
|||
//
|
|||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const domain = require('domain'); |
|||
|
|||
// no matter what happens, we should increment a 10 times.
|
|||
let a = 0; |
|||
log(); |
|||
function log() { |
|||
console.log(a++, process.domain); |
|||
if (a < 10) setTimeout(log, 20); |
|||
} |
|||
|
|||
// in 50ms we'll throw an error.
|
|||
setTimeout(err, 50); |
|||
function err() { |
|||
const d = domain.create(); |
|||
d.on('error', handle); |
|||
d.run(err2); |
|||
|
|||
function err2() { |
|||
// this timeout should never be called, since the domain gets
|
|||
// disposed when the error happens.
|
|||
setTimeout(common.mustNotCall(), 1); |
|||
|
|||
// this function doesn't exist, and throws an error as a result.
|
|||
err3(); // eslint-disable-line no-undef
|
|||
} |
|||
|
|||
function handle(e) { |
|||
// this should clean up everything properly.
|
|||
d.dispose(); |
|||
console.error(e); |
|||
console.error('in handler', process.domain, process.domain === d); |
|||
} |
|||
} |
|||
|
|||
process.on('exit', function() { |
|||
assert.strictEqual(a, 10); |
|||
console.log('ok'); |
|||
}); |
@ -1,46 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
// https://github.com/nodejs/node/pull/2540/files#r38231197
|
|||
|
|||
const common = require('../common'); |
|||
const timers = require('timers'); |
|||
const assert = require('assert'); |
|||
const domain = require('domain'); |
|||
|
|||
// Crazy stuff to keep the process open,
|
|||
// then close it when we are actually done.
|
|||
const TEST_DURATION = common.platformTimeout(1000); |
|||
const keepOpen = setTimeout(function() { |
|||
throw new Error('Test timed out. keepOpen was not canceled.'); |
|||
}, TEST_DURATION); |
|||
|
|||
const endTest = makeTimer(2); |
|||
|
|||
const someTimer = makeTimer(1); |
|||
someTimer.domain = domain.create(); |
|||
someTimer.domain.dispose(); |
|||
someTimer._onTimeout = function() { |
|||
throw new Error('someTimer was not supposed to fire!'); |
|||
}; |
|||
|
|||
endTest._onTimeout = common.mustCall(function() { |
|||
assert.strictEqual(someTimer._idlePrev, null); |
|||
assert.strictEqual(someTimer._idleNext, null); |
|||
clearTimeout(keepOpen); |
|||
}); |
|||
|
|||
const cancelsTimer = makeTimer(1); |
|||
cancelsTimer._onTimeout = common.mustCall(function() { |
|||
someTimer._idleTimeout = 0; |
|||
}); |
|||
|
|||
timers._unrefActive(cancelsTimer); |
|||
timers._unrefActive(someTimer); |
|||
timers._unrefActive(endTest); |
|||
|
|||
function makeTimer(msecs) { |
|||
const timer = {}; |
|||
timers.unenroll(timer); |
|||
timers.enroll(timer, msecs); |
|||
return timer; |
|||
} |
Loading…
Reference in new issue