Skip to content

Commit 602fd36

Browse files
addaleaxBridgeAR
authored andcommitted
domain: remove .dispose()
`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: 4a74fc9 PR-URL: #15412 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 750c080 commit 602fd36

12 files changed

+17
-336
lines changed

doc/api/deprecations.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ instead.
146146
<a id="DEP0012"></a>
147147
### DEP0012: Domain.dispose
148148

149-
Type: Runtime
149+
Type: End-of-Life
150150

151-
[`Domain.dispose()`][] is deprecated. Recover from failed I/O actions
151+
[`Domain.dispose()`][] is removed. Recover from failed I/O actions
152152
explicitly via error event handlers set on the domain instead.
153153

154154
<a id="DEP0013"></a>

doc/api/domain.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ added.
217217

218218
Implicit binding routes thrown errors and `'error'` events to the
219219
Domain's `'error'` event, but does not register the EventEmitter on the
220-
Domain, so [`domain.dispose()`][] will not shut down the EventEmitter.
220+
Domain.
221221
Implicit binding only takes care of thrown errors and `'error'` events.
222222

223223
## Explicit Binding
@@ -329,15 +329,6 @@ d.on('error', (er) => {
329329
});
330330
```
331331

332-
### domain.dispose()
333-
334-
> Stability: 0 - Deprecated. Please recover from failed IO actions
335-
> explicitly via error event handlers set on the domain.
336-
337-
Once `dispose` has been called, the domain will no longer be used by callbacks
338-
bound into the domain via `run`, `bind`, or `intercept`, and a `'dispose'` event
339-
is emitted.
340-
341332
### domain.enter()
342333

343334
The `enter` method is plumbing used by the `run`, `bind`, and `intercept`
@@ -351,9 +342,6 @@ Calling `enter` changes only the active domain, and does not alter the domain
351342
itself. `enter` and `exit` can be called an arbitrary number of times on a
352343
single domain.
353344

354-
If the domain on which `enter` is called has been disposed, `enter` will return
355-
without setting the domain.
356-
357345
### domain.exit()
358346

359347
The `exit` method exits the current domain, popping it off the domain stack.
@@ -369,9 +357,6 @@ Calling `exit` changes only the active domain, and does not alter the domain
369357
itself. `enter` and `exit` can be called an arbitrary number of times on a
370358
single domain.
371359

372-
If the domain on which `exit` is called has been disposed, `exit` will return
373-
without exiting the domain.
374-
375360
### domain.intercept(callback)
376361

377362
* `callback` {Function} The callback function
@@ -500,7 +485,6 @@ rejections.
500485
[`EventEmitter`]: events.html#events_class_eventemitter
501486
[`domain.add(emitter)`]: #domain_domain_add_emitter
502487
[`domain.bind(callback)`]: #domain_domain_bind_callback
503-
[`domain.dispose()`]: #domain_domain_dispose
504488
[`domain.exit()`]: #domain_domain_exit
505489
[`setInterval()`]: timers.html#timers_setinterval_callback_delay_args
506490
[`setTimeout()`]: timers.html#timers_settimeout_callback_delay_args

lib/domain.js

+4-44
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,12 @@ function Domain() {
7575
}
7676

7777
Domain.prototype.members = undefined;
78-
Domain.prototype._disposed = undefined;
7978

8079

8180
// Called by process._fatalException in case an error was thrown.
8281
Domain.prototype._errorHandler = function _errorHandler(er) {
8382
var caught = false;
8483

85-
// ignore errors on disposed domains.
86-
//
87-
// XXX This is a bit stupid. We should probably get rid of
88-
// domain.dispose() altogether. It's almost always a terrible
89-
// idea. --isaacs
90-
if (this._disposed)
91-
return true;
92-
9384
if (!util.isPrimitive(er)) {
9485
er.domain = this;
9586
er.domainThrown = true;
@@ -160,8 +151,6 @@ Domain.prototype._errorHandler = function _errorHandler(er) {
160151

161152

162153
Domain.prototype.enter = function() {
163-
if (this._disposed) return;
164-
165154
// note that this might be a no-op, but we still need
166155
// to push it onto the stack so that we can pop it later.
167156
exports.active = process.domain = this;
@@ -171,10 +160,9 @@ Domain.prototype.enter = function() {
171160

172161

173162
Domain.prototype.exit = function() {
174-
// skip disposed domains, as usual, but also don't do anything if this
175-
// domain is not on the stack.
163+
// don't do anything if this domain is not on the stack.
176164
var index = stack.lastIndexOf(this);
177-
if (this._disposed || index === -1) return;
165+
if (index === -1) return;
178166

179167
// exit all domains until this one.
180168
stack.splice(index);
@@ -187,8 +175,8 @@ Domain.prototype.exit = function() {
187175

188176
// note: this works for timers as well.
189177
Domain.prototype.add = function(ee) {
190-
// If the domain is disposed or already added, then nothing left to do.
191-
if (this._disposed || ee.domain === this)
178+
// If the domain is already added, then nothing left to do.
179+
if (ee.domain === this)
192180
return;
193181

194182
// has a domain already - remove it first.
@@ -224,9 +212,6 @@ Domain.prototype.remove = function(ee) {
224212

225213

226214
Domain.prototype.run = function(fn) {
227-
if (this._disposed)
228-
return;
229-
230215
var ret;
231216

232217
this.enter();
@@ -248,9 +233,6 @@ Domain.prototype.run = function(fn) {
248233

249234

250235
function intercepted(_this, self, cb, fnargs) {
251-
if (self._disposed)
252-
return;
253-
254236
if (fnargs[0] && fnargs[0] instanceof Error) {
255237
var er = fnargs[0];
256238
util._extend(er, {
@@ -291,9 +273,6 @@ Domain.prototype.intercept = function(cb) {
291273

292274

293275
function bound(_this, self, cb, fnargs) {
294-
if (self._disposed)
295-
return;
296-
297276
var ret;
298277

299278
self.enter();
@@ -318,22 +297,3 @@ Domain.prototype.bind = function(cb) {
318297

319298
return runBound;
320299
};
321-
322-
323-
Domain.prototype.dispose = util.deprecate(function() {
324-
if (this._disposed) return;
325-
326-
// if we're the active domain, then get out now.
327-
this.exit();
328-
329-
// remove from parent domain, if there is one.
330-
if (this.domain) this.domain.remove(this);
331-
332-
// kill the references so that they can be properly gc'ed.
333-
this.members.length = 0;
334-
335-
// mark this domain as 'no longer relevant'
336-
// so that it can't be entered or activated.
337-
this._disposed = true;
338-
}, 'Domain.dispose is deprecated. Recover from failed I/O actions explicitly ' +
339-
'via error event handlers set on the domain instead.', 'DEP0012');

lib/timers.js

-9
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,6 @@ function listOnTimeout() {
250250

251251
var domain = timer.domain;
252252
if (domain) {
253-
254-
// If the timer callback throws and the
255-
// domain or uncaughtException handler ignore the exception,
256-
// other timers that expire on this tick should still run.
257-
//
258-
// https://github.com/nodejs/node-v0.x-archive/issues/2631
259-
if (domain._disposed)
260-
continue;
261-
262253
domain.enter();
263254
}
264255

src/env.h

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ struct performance_state;
116116
V(dest_string, "dest") \
117117
V(destroy_string, "destroy") \
118118
V(detached_string, "detached") \
119-
V(disposed_string, "_disposed") \
120119
V(dns_a_string, "A") \
121120
V(dns_aaaa_string, "AAAA") \
122121
V(dns_cname_string, "CNAME") \

src/node.cc

+4-13
Original file line numberDiff line numberDiff line change
@@ -1159,12 +1159,10 @@ bool ShouldAbortOnUncaughtException(Isolate* isolate) {
11591159
}
11601160

11611161

1162-
bool DomainEnter(Environment* env, Local<Object> object) {
1162+
void DomainEnter(Environment* env, Local<Object> object) {
11631163
Local<Value> domain_v = object->Get(env->domain_string());
11641164
if (domain_v->IsObject()) {
11651165
Local<Object> domain = domain_v.As<Object>();
1166-
if (domain->Get(env->disposed_string())->IsTrue())
1167-
return true;
11681166
Local<Value> enter_v = domain->Get(env->enter_string());
11691167
if (enter_v->IsFunction()) {
11701168
if (enter_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) {
@@ -1173,16 +1171,13 @@ bool DomainEnter(Environment* env, Local<Object> object) {
11731171
}
11741172
}
11751173
}
1176-
return false;
11771174
}
11781175

11791176

1180-
bool DomainExit(Environment* env, v8::Local<v8::Object> object) {
1177+
void DomainExit(Environment* env, v8::Local<v8::Object> object) {
11811178
Local<Value> domain_v = object->Get(env->domain_string());
11821179
if (domain_v->IsObject()) {
11831180
Local<Object> domain = domain_v.As<Object>();
1184-
if (domain->Get(env->disposed_string())->IsTrue())
1185-
return true;
11861181
Local<Value> exit_v = domain->Get(env->exit_string());
11871182
if (exit_v->IsFunction()) {
11881183
if (exit_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) {
@@ -1191,7 +1186,6 @@ bool DomainExit(Environment* env, v8::Local<v8::Object> object) {
11911186
}
11921187
}
11931188
}
1194-
return false;
11951189
}
11961190

11971191

@@ -1398,9 +1392,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
13981392
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
13991393

14001394
if (env->using_domains()) {
1401-
failed_ = DomainEnter(env, object_);
1402-
if (failed_)
1403-
return;
1395+
DomainEnter(env, object_);
14041396
}
14051397

14061398
if (asyncContext.async_id != 0) {
@@ -1432,8 +1424,7 @@ void InternalCallbackScope::Close() {
14321424
}
14331425

14341426
if (env_->using_domains()) {
1435-
failed_ = DomainExit(env_, object_);
1436-
if (failed_) return;
1427+
DomainExit(env_, object_);
14371428
}
14381429

14391430
if (IsInnerMakeCallback()) {

test/parallel/test-domain-abort-when-disposed.js

-25
This file was deleted.

test/parallel/test-domain-exit-dispose-again.js

-97
This file was deleted.

0 commit comments

Comments
 (0)