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 2, 2019
1 parent 8eee722 commit 8c45bcf
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit 8c45bcf

Please sign in to comment.