fix: attach finally cleanup to returned promise to avoid unhandled rejections

This commit is contained in:
tone
2025-10-15 17:12:57 +08:00
parent 387cbc0b25
commit 3b9cc6dffb

View File

@@ -110,11 +110,6 @@ export class RPCConnection extends EventEmitter<RPCConnectionEvents> {
return () => clearTimeout(t);
})();
promise.finally(() => {
this.callResponseEmitter.removeAllListeners(packet.id);
cancelTimeoutTimer();
})
const handleCallResponsePacket = (packet: RPCPacket) => {
const result = parseCallResponsePacket(packet);
if (result === null) {
@@ -144,7 +139,10 @@ export class RPCConnection extends EventEmitter<RPCConnectionEvents> {
/** send call request */
this.socket.send(packet);
return promise;
return promise.finally(() => {
this.callResponseEmitter.removeAllListeners(packet.id);
cancelTimeoutTimer();
});
}
public onCallRequest(getProvider: () => RPCProvider | undefined) {
@@ -220,4 +218,8 @@ export class RPCConnection extends EventEmitter<RPCConnectionEvents> {
return null;
}
}
public async close() {
return this.socket.close();
}
}