Skip to content

Commit

Permalink
fix: Update request method in windows Client interface to blocking ca…
Browse files Browse the repository at this point in the history
…ll. (#90)

Signed-off-by: Hongli Chen <honglich@amazon.com>
  • Loading branch information
Honglichenn authored Mar 22, 2024
1 parent 7440c53 commit e66d592
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 11 additions & 8 deletions src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
*,
Expand All @@ -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.
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/openjd/adaptor_runtime_client/win_client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e66d592

Please sign in to comment.