Skip to content

Commit 396f65a

Browse files
committed
stop sending unref if disconnected
1 parent 690361d commit 396f65a

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/node/node-wsh.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class WindowsScriptingHost extends EventEmitter {
1717
}
1818

1919
#syncline;
20+
#closed = false;
2021
#finalizer = new FinalizationRegistry( this.#finalized.bind( this));
2122
#ref2proxy = new Map();
2223
#proxy2ref = new WeakMap();
@@ -99,6 +100,7 @@ export class WindowsScriptingHost extends EventEmitter {
99100
}
100101

101102
async disconnect() {
103+
this.#closed = true;
102104
await this.#syncline.close();
103105
}
104106

@@ -121,7 +123,8 @@ export class WindowsScriptingHost extends EventEmitter {
121123
#finalized( ref) {
122124
if( this.#ref2proxy.get( ref).deref() === undefined) // otherwise, it's overwritten by a refreshed proxy
123125
this.#ref2proxy.delete( ref);
124-
const output = this.#syncline.exchange( JSON.stringify( [ 'unref', ref]));
126+
if( !this.#closed)
127+
this.#syncline.exchange( JSON.stringify( [ 'unref', ref]));
125128
this.emit( 'unref', ref);
126129
}
127130

0 commit comments

Comments
 (0)