Skip to content

Commit dd2a909

Browse files
committed
exit handler fix
1 parent 6794a62 commit dd2a909

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

lib/agent.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Agent {
4545

4646
self.isProfiling = false;
4747
self.profilerLock = false;
48+
49+
self.exitHandlerFunc = undefined;
4850
}
4951

5052

@@ -87,22 +89,6 @@ class Agent {
8789
}
8890

8991

90-
exitHandler() {
91-
let self = this;
92-
93-
if (!self.agentStarted || self.agentDestroyed) {
94-
return;
95-
}
96-
97-
try {
98-
self.destroy();
99-
}
100-
catch(err) {
101-
self.exception(err);
102-
}
103-
}
104-
105-
10692
start(opts) {
10793
let self = this;
10894

@@ -170,7 +156,20 @@ class Agent {
170156
self.messageQueue.start();
171157

172158

173-
process.once('exit', self.exitHandler);
159+
self.exitHandlerFunc = function() {
160+
if (!self.agentStarted || self.agentDestroyed) {
161+
return;
162+
}
163+
164+
try {
165+
self.destroy();
166+
}
167+
catch(err) {
168+
self.exception(err);
169+
}
170+
}
171+
172+
process.once('exit', self.exitHandlerFunc);
174173

175174
self.agentStarted = true;
176175
self.log('Agent started');
@@ -189,7 +188,7 @@ class Agent {
189188
return;
190189
}
191190

192-
process.removeListener('exit', self.exitHandler);
191+
process.removeListener('exit', self.exitHandlerFunc);
193192

194193
self.cpuReporter.stop();
195194
self.allocationReporter.stop();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stackimpact",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "StackImpact Node.js Agent",
55
"author": "StackImpact <devops@stackimpact.com>",
66
"keywords": [

0 commit comments

Comments
 (0)