Stopping a live flow ends the calls it has running, on workers and in the local pool, and deleting one now ends its local calls too; what a call returns after its flow was stopped or deleted is dropped by a per-flow count the node compares, so a flow started again never takes an old call's answer. A live remote call's id carries a suffix, so two calls of one node no longer share it, and a call is registered before it queues for a slot, so ending its flow or run reaches it and it is never sent; a run's cancel goes through the call's own thread as well
This commit is contained in:
@@ -699,7 +699,9 @@ class FlowController:
|
||||
else:
|
||||
self.disabled = self.disabled | {flow}
|
||||
self.pipeline.set_disabled(self.disabled)
|
||||
self.pipeline.end_running(flow)
|
||||
await self._teardown(flow)
|
||||
await self._end_calls(flow)
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
@@ -862,10 +864,7 @@ class FlowController:
|
||||
if built is None:
|
||||
if name:
|
||||
pipeline.remove_flow(name)
|
||||
# A call still out on a worker would keep its slot and its
|
||||
# process there, for a result that is now dropped.
|
||||
if self.remote is not None:
|
||||
self.remote.cancel_flow(name)
|
||||
await self._end_calls(name)
|
||||
self.loaded = {
|
||||
node_id: entry
|
||||
for node_id, entry in self.loaded.items()
|
||||
@@ -1142,6 +1141,26 @@ class FlowController:
|
||||
else:
|
||||
await self.supervisor.cancel_flow(flow)
|
||||
|
||||
async def _end_calls(self, flow: str) -> None:
|
||||
"""End the calls a stopped or deleted flow has running, here and on
|
||||
workers. A call left out there would keep its slot and its process for
|
||||
a result that is dropped (`Pipeline.end_running`)."""
|
||||
if self.remote is not None:
|
||||
self.remote.cancel_flow(flow)
|
||||
pool = self.workers
|
||||
if pool is None:
|
||||
return
|
||||
nodes = [
|
||||
node_id for node_id, entry in self.loaded.items() if entry.flow == flow
|
||||
]
|
||||
|
||||
def cancel() -> None:
|
||||
for node_id in nodes:
|
||||
pool.cancel(node_id)
|
||||
|
||||
# Off the loop: a killed worker is waited for.
|
||||
await run_in_threadpool(cancel)
|
||||
|
||||
async def _activate(self, flow: str | None = None) -> None:
|
||||
"""Start subscriptions, schedules and webhooks of the new pipeline.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user