Skip to content

Commit 6fdf6b9

Browse files
committed
iris: clean up terminal operations from server memory
Clean up completed/failed/cancelled operations from `_operations` on `get_operation` poll. Previously terminal operations would accumulate in server memory indefinitely.
1 parent 2d7123b commit 6fdf6b9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/iris/src/iris/actor/server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,20 @@ def run():
266266
return op.to_proto()
267267

268268
async def get_operation(self, request: actor_pb2.OperationId, ctx: RequestContext) -> actor_pb2.Operation:
269-
"""Poll the state of a long-running operation."""
269+
"""Poll the state of a long-running operation.
270+
271+
When the operation reaches a terminal state (SUCCEEDED, FAILED, CANCELLED),
272+
the result is returned and the operation is removed from server memory.
273+
"""
270274
with self._operations_lock:
271275
op = self._operations.get(request.operation_id)
272276
if op is None:
273277
raise ConnectError(Code.NOT_FOUND, f"Operation '{request.operation_id}' not found")
274-
return op.to_proto()
278+
proto = op.to_proto()
279+
if proto.state not in (actor_pb2.Operation.PENDING, actor_pb2.Operation.RUNNING):
280+
with self._operations_lock:
281+
self._operations.pop(request.operation_id, None)
282+
return proto
275283

276284
async def cancel_operation(self, request: actor_pb2.OperationId, ctx: RequestContext) -> actor_pb2.Operation:
277285
"""Request cancellation of a long-running operation.

0 commit comments

Comments
 (0)