mirror of
https://github.com/koush/scrypted.git
synced 2026-05-26 14:40:29 +01:00
rpc: dont throw on oneway methods even if the peer is closed
This commit is contained in:
@@ -159,13 +159,18 @@ class RpcProxy implements PrimitiveProxyHandler<any> {
|
||||
}
|
||||
|
||||
apply(target: any, thisArg: any, argArray?: any): any {
|
||||
if (Object.isFrozen(this.peer.pendingResults))
|
||||
return Promise.reject(new RPCResultError(this.peer, 'RpcPeer has been killed'));
|
||||
const method = target() || null;
|
||||
const oneway = this.proxyOneWayMethods?.includes?.(method);
|
||||
|
||||
if (Object.isFrozen(this.peer.pendingResults)) {
|
||||
if (oneway)
|
||||
return Promise.resolve();
|
||||
return Promise.reject(new RPCResultError(this.peer, 'RpcPeer has been killed (apply) ' + target()));
|
||||
}
|
||||
|
||||
// rpc objects can be functions. if the function is a oneway method,
|
||||
// it will have a null in the oneway method list. this is because
|
||||
// undefined is not JSON serializable.
|
||||
const method = target() || null;
|
||||
const args: any[] = [];
|
||||
const serializationContext: any = {};
|
||||
for (const arg of (argArray || [])) {
|
||||
@@ -180,7 +185,7 @@ class RpcProxy implements PrimitiveProxyHandler<any> {
|
||||
method,
|
||||
};
|
||||
|
||||
if (this.proxyOneWayMethods?.includes?.(method)) {
|
||||
if (oneway) {
|
||||
rpcApply.oneway = true;
|
||||
// a oneway callable object doesn't need to be in the JSON payload.
|
||||
if (method === null)
|
||||
@@ -390,7 +395,7 @@ export class RpcPeer {
|
||||
|
||||
createPendingResult(cb: (id: string, reject: (e: Error) => void) => void): Promise<any> {
|
||||
if (Object.isFrozen(this.pendingResults))
|
||||
return Promise.reject(new RPCResultError(this, 'RpcPeer has been killed'));
|
||||
return Promise.reject(new RPCResultError(this, 'RpcPeer has been killed (createPendingResult)'));
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const id = (this.idCounter++).toString();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WARNING: threading.ts does not work because RpcPeer transpilation does not include readonly static properties in the class definition
|
||||
|
||||
import worker_threads from 'worker_threads';
|
||||
import { getEvalSource, RpcPeer } from './rpc';
|
||||
import v8 from 'v8';
|
||||
|
||||
Reference in New Issue
Block a user