Skip to content

Commit

Permalink
fix: run health servicer in thread to allow readinessProbe while req
Browse files Browse the repository at this point in the history
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
  • Loading branch information
JoanFM committed Nov 17, 2022
1 parent 63cde2d commit 32dcbc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion jina/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ def __init__(self, args: 'argparse.Namespace'):
) as tc:
if args.target == 'executor':
hostname, port, protocol, _ = parse_host_scheme(args.host)
r = WorkerRuntime.is_ready(f'{hostname}:{port}')
r = WorkerRuntime.is_ready(ctrl_address=f'{hostname}:{port}', timeout=args.timeout)
elif args.target == 'gateway':
hostname, port, protocol, _ = parse_host_scheme(args.host)
r = GatewayRuntime.is_ready(
f'{hostname}:{port}',
protocol=GatewayProtocolType.from_string(protocol),
timeout=args.timeout
)
elif args.target == 'flow':
r = Client(host=args.host).is_flow_ready(timeout=args.timeout)
Expand Down
7 changes: 4 additions & 3 deletions jina/serve/runtimes/worker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
from abc import ABC
from typing import TYPE_CHECKING, List, Optional
from concurrent.futures import ThreadPoolExecutor

import grpc
from grpc_health.v1 import health, health_pb2, health_pb2_grpc
Expand Down Expand Up @@ -32,7 +33,7 @@ def __init__(
:param args: args from CLI
:param kwargs: keyword args
"""
self._health_servicer = health.aio.HealthServicer()
self._health_servicer = health.HealthServicer(experimental_thread_pool=ThreadPoolExecutor(1))
super().__init__(args, **kwargs)

async def async_setup(self):
Expand Down Expand Up @@ -140,7 +141,7 @@ async def _async_setup_grpc_server(self):
)

for service in service_names:
await self._health_servicer.set(
self._health_servicer.set(
service, health_pb2.HealthCheckResponse.SERVING
)
reflection.enable_server_reflection(service_names, self._grpc_server)
Expand All @@ -164,7 +165,7 @@ async def async_cancel(self):

async def async_teardown(self):
"""Close the data request handler"""
await self._health_servicer.enter_graceful_shutdown()
self._health_servicer.enter_graceful_shutdown()
await self.async_cancel()
self._request_handler.close()

Expand Down

0 comments on commit 32dcbc2

Please sign in to comment.