From 8cbcd92c1f44c0ddb605d1bb5e093cdaf47b4303 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Mon, 4 Mar 2024 04:51:05 +0300 Subject: [PATCH] fix: send empty packet to the client every 600 seconds --- src/isolate/server/server.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/isolate/server/server.py b/src/isolate/server/server.py index ccd8bae..bff10d9 100644 --- a/src/isolate/server/server.py +++ b/src/isolate/server/server.py @@ -2,6 +2,7 @@ import os import threading +import time import traceback from collections import defaultdict from concurrent import futures @@ -32,6 +33,7 @@ from isolate.server.health_server import HealthServicer from isolate.server.interface import from_grpc, to_grpc +EMPTY_MESSAGE_INTERVAL = float(os.getenv("ISOLATE_EMPTY_MESSAGE_INTERVAL", 600)) MAX_GRPC_WAIT_TIMEOUT = float(os.getenv("ISOLATE_MAX_GRPC_WAIT_TIMEOUT", 10.0)) # Whether to inherit all the packages from the current environment or not. @@ -299,11 +301,21 @@ def watch_queue_until_completed( """Watch the given queue until the is_completed function returns True. Note that even if the function is completed, this function might not finish until the queue is empty. """ + + timer = time.monotonic() while not is_completed(): try: yield queue.get(timeout=_Q_WAIT_DELAY) except QueueEmpty: - continue + # Send an empty (but 'real') packet to the client, currently a hacky way + # to make sure the stream results are never ignored. + if time.monotonic() - timer > EMPTY_MESSAGE_INTERVAL: + timer = time.monotonic() + yield definitions.PartialRunResult( + is_complete=False, + logs=[], + result=None, + ) # Clear the final messages while not queue.empty():