Skip to content

Commit d00e950

Browse files
committed
fix(uart): leaking event listener on process exit
1 parent 5c391ae commit d00e950

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/uart.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class BluetoothHciSocket extends EventEmitter {
2525
this._queue = null;
2626
this._parser = null;
2727
this._exitHandler = this.reset.bind(this);
28-
process.on('exit', this._exitHandler);
2928
}
3029

3130
setFilter (filter) {
@@ -206,6 +205,7 @@ class BluetoothHciSocket extends EventEmitter {
206205

207206
if (!this._serialDevice.isOpen) {
208207
this._serialDevice.open();
208+
process.on('exit', this._exitHandler);
209209
}
210210

211211
this._hciSerialParser.removeAllListeners('data');
@@ -217,6 +217,9 @@ class BluetoothHciSocket extends EventEmitter {
217217
}
218218

219219
stop () {
220+
// Remove the exit listener
221+
process.removeListener('exit', this._exitHandler);
222+
220223
if (this._mode !== 'raw' && this._mode !== 'user') {
221224
return;
222225
}
@@ -225,8 +228,6 @@ class BluetoothHciSocket extends EventEmitter {
225228
this._serialDevice.close();
226229
}
227230

228-
process.removeListener('exit', this._exitHandler);
229-
230231
this._isReconnectionCancelled = true;
231232
this._hciSerialParser.removeAllListeners('data');
232233
this._serialDevice.removeAllListeners();

0 commit comments

Comments
 (0)