From e66d5927f6f0ede574ae39bcd2616042265baa7c Mon Sep 17 00:00:00 2001 From: Hongli Chen <94642294+Honglichenn@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:20:38 -0700 Subject: [PATCH] fix: Update request method in windows Client interface to blocking call. (#90) Signed-off-by: Hongli Chen --- .../named_pipe/named_pipe_config.py | 2 ++ .../named_pipe/named_pipe_helper.py | 19 +++++++++++-------- .../win_client_interface.py | 5 +++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_config.py b/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_config.py index 7bc7697..f469ecb 100644 --- a/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_config.py +++ b/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_config.py @@ -6,3 +6,5 @@ # This number must be >= 2, one instance is for normal operation communication # and the other one is for immediate shutdown communication DEFAULT_MAX_NAMED_PIPE_INSTANCES = 4 +# The maximum time in seconds to wait for the server pipe to become available before raising an error. +DEFAULT_NAMED_PIPE_SERVER_TIMEOUT_IN_SECONDS = 60 diff --git a/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py b/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py index c01501f..cb66e24 100644 --- a/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py +++ b/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py @@ -22,6 +22,7 @@ from .named_pipe_config import ( NAMED_PIPE_BUFFER_SIZE, DEFAULT_MAX_NAMED_PIPE_INSTANCES, + DEFAULT_NAMED_PIPE_SERVER_TIMEOUT_IN_SECONDS, ) _logger = logging.getLogger(__name__) @@ -242,14 +243,14 @@ def read_from_pipe_target(handle: HANDLE): NamedPipeHelper._handle_pipe_exception(e) @staticmethod - def read_from_pipe(handle: HANDLE, timeout_in_seconds: float = 5.0) -> str: # type: ignore + def read_from_pipe(handle: HANDLE, timeout_in_seconds: Optional[float] = 5.0) -> str: # type: ignore """ Reads data from a Named Pipe. Times out after timeout_in_seconds. Args: handle (HANDLE): The handle to the Named Pipe. - timeout_in_seconds (float): The maximum time in seconds to wait for data before - raising a TimeoutError. Defaults to 5 seconds. + timeout_in_seconds (Optional[float]): The maximum time in seconds to wait for data before + raising a TimeoutError. Defaults to 5 seconds. None means waiting indefinitely. Returns: str: The data read from the Named Pipe. @@ -299,7 +300,7 @@ def establish_named_pipe_connection(pipe_name: str, timeout_in_seconds: float) - Args: pipe_name (str): The name of the pipe to connect to. timeout_in_seconds (float): The maximum time in seconds to wait for the server pipe - to become available before raising an error. + to become available before raising an error. If None, the function will wait indefinitely. Returns: HANDLE: A handle to the connected pipe. @@ -360,7 +361,7 @@ def establish_named_pipe_connection(pipe_name: str, timeout_in_seconds: float) - @staticmethod def send_named_pipe_request( pipe_name: str, - timeout_in_seconds: float, + timeout_in_seconds: Optional[float], method: str, path: str, *, @@ -375,8 +376,8 @@ def send_named_pipe_request( Args: pipe_name (str): The name of the pipe to connect to. - timeout_in_seconds (float): The maximum time in seconds to wait for the server pipe to become available - before raising an error. + timeout_in_seconds (Optional[float]): The maximum time in seconds to wait for the server to response. + None means no timeout. method (str): The HTTP method type (e.g., 'GET', 'POST'). path (str): The request path. params (dict, optional): Dictionary of URL parameters to append to the path. @@ -390,7 +391,9 @@ def send_named_pipe_request( json.JSONDecodeError: If there is an error in parsing the server's response. """ - handle = NamedPipeHelper.establish_named_pipe_connection(pipe_name, timeout_in_seconds) + handle = NamedPipeHelper.establish_named_pipe_connection( + pipe_name, DEFAULT_NAMED_PIPE_SERVER_TIMEOUT_IN_SECONDS + ) try: message_dict = { "method": method, diff --git a/src/openjd/adaptor_runtime_client/win_client_interface.py b/src/openjd/adaptor_runtime_client/win_client_interface.py index 7fbda98..fa211cd 100644 --- a/src/openjd/adaptor_runtime_client/win_client_interface.py +++ b/src/openjd/adaptor_runtime_client/win_client_interface.py @@ -11,7 +11,8 @@ from .named_pipe.named_pipe_helper import NamedPipeHelper -_DEFAULT_TIMEOUT_IN_SECONDS = 15 +# Set timeout to None so our requests are blocking calls with no timeout. +_REQUEST_TIMEOUT = None class WinClientInterface(BaseClientInterface): @@ -40,7 +41,7 @@ def _send_request( query_string_params = {key: [value] for key, value in query_string_params.items()} json_result = NamedPipeHelper.send_named_pipe_request( self.server_path, - _DEFAULT_TIMEOUT_IN_SECONDS, + _REQUEST_TIMEOUT, method, path, params=query_string_params,