Skip to content

Commit e648d49

Browse files
author
Peter Marton
authored
fix(server): address domain performance regression with Node v12.x (#1809)
1 parent b8ec60e commit e648d49

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/server.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
'use strict';
44

5-
var domain = require('domain');
65
var EventEmitter = require('events').EventEmitter;
76
var http = require('http');
87
var https = require('https');
@@ -27,6 +26,7 @@ var customErrorTypes = require('./errorTypes');
2726
var patchRequest = require('./request');
2827
var patchResponse = require('./response');
2928

29+
var domain;
3030
var http2;
3131

3232
patchResponse(http.ServerResponse);
@@ -930,6 +930,14 @@ Server.prototype._onRequest = function _onRequest(req, res) {
930930
// It has significant negative performance impact
931931
// Warning: this feature depends on the deprecated domains module
932932
if (self.handleUncaughtExceptions) {
933+
// In Node v12.x requiring the domain module has a negative performance
934+
// impact. As using domains in restify is optional and only required
935+
// with the `handleUncaughtExceptions` options, we apply a singleton
936+
// pattern to avoid any performance regression in the default scenario.
937+
if (!domain) {
938+
domain = require('domain');
939+
}
940+
933941
var handlerDomain = domain.create();
934942
handlerDomain.add(req);
935943
handlerDomain.add(res);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"once": "^1.4.0",
109109
"pidusage": "^2.0.17",
110110
"qs": "^6.7.0",
111-
"restify-errors": "^8.0.0",
111+
"restify-errors": "^8.0.2",
112112
"semver": "^6.1.1",
113113
"send": "^0.16.2",
114114
"spdy": "^4.0.0",

0 commit comments

Comments
 (0)