Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): address domain performance regression with Node v12.x #1809

Merged
merged 2 commits into from Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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