File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33'use strict' ;
44
5- var domain = require ( 'domain' ) ;
65var EventEmitter = require ( 'events' ) . EventEmitter ;
76var http = require ( 'http' ) ;
87var https = require ( 'https' ) ;
@@ -27,6 +26,7 @@ var customErrorTypes = require('./errorTypes');
2726var patchRequest = require ( './request' ) ;
2827var patchResponse = require ( './response' ) ;
2928
29+ var domain ;
3030var http2 ;
3131
3232patchResponse ( 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 ) ;
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments