mirror of
https://github.com/koush/scrypted.git
synced 2026-05-04 21:30:30 +01:00
server: fix connectRPCObject gc race condition
This commit is contained in:
@@ -417,6 +417,10 @@ class PluginRemote:
|
||||
def onProxySerialization(value: Any, proxyId: str, sourcePeerPort: int = None):
|
||||
properties: dict = rpc.RpcPeer.prepareProxyProperties(value) or {}
|
||||
clusterEntry = properties.get('__cluster', None)
|
||||
|
||||
if clusterEntry and clusterPort == clusterEntry['port'] and sourcePeerPort != clusterEntry.get('sourcePort', None):
|
||||
clusterEntry = None
|
||||
|
||||
if not properties.get('__cluster', None):
|
||||
clusterEntry: ClusterObject = {
|
||||
'id': clusterId,
|
||||
|
||||
@@ -100,6 +100,12 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe
|
||||
const properties = RpcPeer.prepareProxyProperties(value) || {};
|
||||
let clusterEntry: ClusterObject = properties.__cluster;
|
||||
|
||||
// if the cluster entry already exists, check if it belongs to this node.
|
||||
// if it belongs to this node, the entry must also be for this peer.
|
||||
// relying on the liveness/gc of a different peer may cause race conditions.
|
||||
if (clusterEntry && clusterPort === clusterEntry.port && sourcePeerPort !== clusterEntry.sourcePort)
|
||||
clusterEntry = undefined;
|
||||
|
||||
// set the cluster identity if it does not exist.
|
||||
if (!clusterEntry) {
|
||||
clusterEntry = {
|
||||
@@ -112,11 +118,7 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe
|
||||
clusterEntry.sha256 = computeClusterObjectHash(clusterEntry, clusterSecret);
|
||||
properties.__cluster = clusterEntry;
|
||||
}
|
||||
// always reassign the id and source.
|
||||
// if this is already a p2p object, and is passed to a different peer,
|
||||
// a future p2p object must be routed to the correct p2p peer to find the object.
|
||||
// clusterEntry.proxyId = proxyId;
|
||||
// clusterEntry.source = source;
|
||||
|
||||
return properties;
|
||||
}
|
||||
peer.onProxySerialization = onProxySerialization;
|
||||
|
||||
Reference in New Issue
Block a user