Deleting a live flow ends the calls it has out on workers and drops what a removed node still returns, so a node that never returns gives its slot and process back and a late answer no longer recreates the flow's values; a cancel goes through the call's own inbox and is sent after the call's frame, so a service stopped right after starting no longer cancels before its serve

This commit is contained in:
2026-11-11 09:40:59 +01:00
parent 138c632576
commit a3d532f3a5
8 changed files with 187 additions and 12 deletions
+7 -3
View File
@@ -264,15 +264,16 @@ class Node:
if self._on_health is not None:
self._on_health(self, status, detail)
def bind(self, pipeline: Pipeline) -> None:
def bind(self, pipeline: Pipeline | None) -> None:
"""
Bind this node to a pipeline for external triggering.
Once bound, the node can trigger downstream execution when called.
This is typically done automatically during pipeline construction.
:param pipeline: The pipeline to bind this node to.
:type pipeline: Pipeline
:param pipeline: The pipeline to bind this node to, or None once its
flow has been taken out of the graph.
:type pipeline: Pipeline | None
"""
self._pipeline = pipeline
@@ -466,6 +467,9 @@ class Node:
collected = logs.Collector()
with logs.capture(collected):
outputs = self.f(params=self.params) or {}
if self._pipeline is None:
# Its flow was deleted while it ran (`Pipeline.remove_flow`).
return None
self._pipeline.publish_log(self, collected, "")
return self._pipeline.trigger(self, self._to_messages(outputs), durable=durable)
+7 -3
View File
@@ -10,6 +10,7 @@ from __future__ import annotations
import asyncio
import logging
import queue
import shlex
import uuid
from collections.abc import Iterable
@@ -169,9 +170,12 @@ class ServiceNode(Node):
"env": self.cfg.env,
"weights": self.cfg.weights,
}
# On a thread, as every call is, and holding no slot.
# On a thread, as every call is, and holding no slot. Its inbox is made
# here, so a stop that comes before the thread has sent the serve can
# still end it, after the serve rather than ahead of it.
inbox: queue.Queue[dict[str, Any] | None] = queue.Queue()
call = asyncio.ensure_future(
asyncio.to_thread(worker.request, payload, 0, slot=False)
asyncio.to_thread(worker.request, payload, 0, slot=False, inbox=inbox)
)
# Retrieved however it ends, so one that outlives a stop is not
# reported at exit.
@@ -197,7 +201,7 @@ class ServiceNode(Node):
# The flow stopped, or this side failed. Ending the call kills
# the server's process group on the worker, and its answer says
# that is done, so the next start finds the port free.
await asyncio.to_thread(worker.cancel, call_id)
inbox.put(worker.END)
await asyncio.wait({call}, timeout=STOP_WAIT_S)
await asyncio.to_thread(self._withdraw)