From aff90632534199360c299e829cb618f675290a2c Mon Sep 17 00:00:00 2001 From: etyp Date: Fri, 7 Sep 2018 00:14:03 -0400 Subject: [PATCH] Track computations from autoruns and ensure they're all stopped on publish stop --- server.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server.coffee b/server.coffee index 0496212..ffe2052 100644 --- a/server.coffee +++ b/server.coffee @@ -162,10 +162,12 @@ extendPublish (name, publishFunction, options) -> return handles = [] + trackedComputations = [] # This autorun is nothing special, just that it makes sure handles are stopped when publish stops, # and that you can return cursors from the function which would be automatically published. publish.autorun = (runFunc) -> handle = Tracker.autorun (computation) -> + trackedComputations.push computation result = runFunc.call publish, computation collectionNames = getCollectionNames result @@ -194,6 +196,12 @@ extendPublish (name, publishFunction, options) -> while handles.length handle = handles.shift() handle?.stop() + # Stop computations in case a subscription is stopped before ready on the client and + # the publish is using meteorhacks:unblock's "this.unblock()". Without this, observers + # created from cursors inside the autorun will exist forever. + while trackedComputations.length + computation = trackedComputations.shift() + computation?.stop() result = publishFunction.apply publish, args