@bian-womp/spark-remote 0.3.52 → 0.3.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/esm/index.js CHANGED
@@ -444,6 +444,24 @@ async function createServerRuntimeAdapter(id, createRegistry, send, extensions)
444
444
  });
445
445
  },
446
446
  build: async (def, opts) => {
447
+ // If we rebuild the graph, we must not keep the previous runtime/engine alive.
448
+ // This can happen for a single "flow" when:
449
+ // - server bootstraps an empty graph (no snapshot) then client sends Build with real def
450
+ // - snapshot load / applySnapshotFull triggers a build
451
+ // - client intentionally rebuilds the graph
452
+ //
453
+ // Without disposing, we can end up with multiple GraphRuntime instances in memory
454
+ // for the same flow/connection, each holding listeners/resources.
455
+ if (engine) {
456
+ console.info(`[ServerRuntimeAdapter:${id}] Disposing previous engine before building new one`);
457
+ engine.dispose();
458
+ engine = undefined;
459
+ }
460
+ if (graphRuntime) {
461
+ console.info(`[ServerRuntimeAdapter:${id}] Disposing previous graph runtime before building new one`);
462
+ graphRuntime.dispose();
463
+ graphRuntime = undefined;
464
+ }
447
465
  const environment = opts?.environment || {};
448
466
  graphRuntime = builder.build(def, {
449
467
  environment,