Skip to content

Commit 7867b5e

Browse files
committed
Prevent "already disposed" errors when trying to kill disposed proxies
1 parent 9de6400 commit 7867b5e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/protocol/src/browser/client.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface ProxyData {
1515
promise: Promise<void>;
1616
instance: any;
1717
callbacks: Map<number, (...args: any[]) => void>;
18+
disposed: boolean;
1819
}
1920

2021
/**
@@ -174,9 +175,10 @@ export class Client {
174175
* Make a remote call for a proxy's method using proto.
175176
*/
176177
private remoteCall(proxyId: number | Module, method: string, args: any[]): Promise<any> {
177-
if (this.disconnected && typeof proxyId === "number") {
178-
// Can assume killing or closing works because a disconnected proxy
179-
// is disposed on the server's side.
178+
if (typeof proxyId === "number" && (this.disconnected || !this.proxies.has(proxyId))) {
179+
// Can assume killing or closing works because a disconnected proxy is
180+
// disposed on the server's side, and a non-existent proxy has already
181+
// been disposed.
180182
switch (method) {
181183
case "close":
182184
case "kill":
@@ -469,6 +471,7 @@ export class Client {
469471
promise,
470472
instance,
471473
callbacks: new Map(),
474+
disposed: false,
472475
});
473476

474477
instance.onDone(() => {

0 commit comments

Comments
 (0)