From 1aa1df885d8e22a8eeaf74dbfcce665aa5097717 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 29 Jul 2024 13:43:52 -0700 Subject: [PATCH] server: fix connectRPCObject gc race condition --- server/python/plugin_remote.py | 4 ++++ server/src/plugin/plugin-remote-worker.ts | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server/python/plugin_remote.py b/server/python/plugin_remote.py index 43891becc..98968e230 100644 --- a/server/python/plugin_remote.py +++ b/server/python/plugin_remote.py @@ -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, diff --git a/server/src/plugin/plugin-remote-worker.ts b/server/src/plugin/plugin-remote-worker.ts index 061d463c7..0b14f80c4 100644 --- a/server/src/plugin/plugin-remote-worker.ts +++ b/server/src/plugin/plugin-remote-worker.ts @@ -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;