File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,21 @@ export const httpCreateServerHack = (): void => {
52
52
socketConnect : start
53
53
} as RequestLog [ "timestamps" ] ;
54
54
55
+ // Creating a domain and wrapping the execution.
56
+ const d = domain . create ( ) ;
57
+
58
+ d . add ( req ) ;
59
+ d . add ( res ) ;
60
+
61
+ const clearDomain = ( ) : void => {
62
+ d . remove ( req ) ;
63
+ d . remove ( res ) ;
64
+
65
+ while ( process . domain ) {
66
+ ( process . domain as domain . Domain ) . exit ( ) ;
67
+ }
68
+ } ;
69
+
55
70
const requestInfo = captureIncoming ( req ) ;
56
71
57
72
res . writeHead = ( ( fn ) : typeof res . writeHead => (
@@ -123,6 +138,8 @@ export const httpCreateServerHack = (): void => {
123
138
timestamps
124
139
} as RequestLog ;
125
140
141
+ clearDomain ( ) ;
142
+
126
143
eventBus . emit ( EVENT_LIST . RESPONSE_FINISH , {
127
144
req, res, context
128
145
} ) ;
@@ -138,11 +155,6 @@ export const httpCreateServerHack = (): void => {
138
155
} ) ;
139
156
} ) ;
140
157
141
- // Creating a domain and wrapping the execution.
142
- const d = domain . create ( ) ;
143
-
144
- d . add ( req ) ;
145
- d . add ( res ) ;
146
158
d . run ( ( ) => {
147
159
// 初始化一下 Context
148
160
currentContext ( ) ;
You can’t perform that action at this time.
0 commit comments