Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send empty packet to the client every 600 seconds #112

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/isolate/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import threading
import time
import traceback
from collections import defaultdict
from concurrent import futures
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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():
Expand Down
Loading