Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/client/services/rpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,19 @@ export class RpcClient implements IRpcMethodRegistrar {
}

async unregisterMethod(methodName: string): Promise<boolean> {
if (!this.jsonRpcServer.hasMethod(methodName)) return false;
if (!this.jsonRpcServer.hasMethod(methodName)) {
logger.warn(`Cannot unregister RPC method ${methodName}: not locally registered`);
return false;
}
const mutex = this.registrationMutexMap.get(methodName);
return mutex.runExclusive(async () => {
if (!this.jsonRpcServer.hasMethod(methodName)) return false;
if (!this.jsonRpcServer.hasMethod(methodName)) {
logger.warn(`Cannot unregister RPC method ${methodName}: not locally registered`);
return false;
}
const successful = await this.jsonRpcClient.request(UNREGISTER_METHOD, [methodName]);
if (successful) this.jsonRpcServer.removeMethod(methodName);
else logger.warn(`Remote failed to unregister RPC method ${methodName}`);
return successful;
});
}
Expand Down
9 changes: 7 additions & 2 deletions src/shared/services/network.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,14 @@ export async function registerRequestHandler(
if (requestHandlerOptions?.timeoutMilliseconds !== undefined)
setTimeoutMsForRequestType(requestType, requestHandlerOptions.timeoutMilliseconds);
return async () => {
if (!jsonRpc) return false;
if (!jsonRpc) {
logger.warn(`Could not unregister request handler for "${requestType}": jsonRpc is not set`);
return false;
}
removeTimeoutMsForRequestType(requestType);
return jsonRpc.unregisterMethod(requestType);
const unregistered = await jsonRpc.unregisterMethod(requestType);
if (!unregistered) logger.warn(`Failed to unregister request handler for "${requestType}"`);
return unregistered;
};
}

Expand Down
Loading