Skip to content

Commit

Permalink
fix(server): address domain performance regression with Node v12.x (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton committed Dec 13, 2019
1 parent b8ec60e commit e648d49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/server.js
Expand Up @@ -2,7 +2,6 @@

'use strict';

var domain = require('domain');
var EventEmitter = require('events').EventEmitter;
var http = require('http');
var https = require('https');
Expand All @@ -27,6 +26,7 @@ var customErrorTypes = require('./errorTypes');
var patchRequest = require('./request');
var patchResponse = require('./response');

var domain;
var http2;

patchResponse(http.ServerResponse);
Expand Down Expand Up @@ -930,6 +930,14 @@ Server.prototype._onRequest = function _onRequest(req, res) {
// It has significant negative performance impact
// Warning: this feature depends on the deprecated domains module
if (self.handleUncaughtExceptions) {
// In Node v12.x requiring the domain module has a negative performance
// impact. As using domains in restify is optional and only required
// with the `handleUncaughtExceptions` options, we apply a singleton
// pattern to avoid any performance regression in the default scenario.
if (!domain) {
domain = require('domain');
}

var handlerDomain = domain.create();
handlerDomain.add(req);
handlerDomain.add(res);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -108,7 +108,7 @@
"once": "^1.4.0",
"pidusage": "^2.0.17",
"qs": "^6.7.0",
"restify-errors": "^8.0.0",
"restify-errors": "^8.0.2",
"semver": "^6.1.1",
"send": "^0.16.2",
"spdy": "^4.0.0",
Expand Down

0 comments on commit e648d49

Please sign in to comment.