Skip to content

Commit

Permalink
Merge pull request #257 from DUNE-DAQ/plasorak/timeouts
Browse files Browse the repository at this point in the history
10 seconds timeout for k8spm
  • Loading branch information
TiagoTAlves authored Mar 28, 2024
2 parents 4bfc087 + 21b28cf commit 9d0a19f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
42 changes: 33 additions & 9 deletions src/nanorc/appctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,15 @@ class AppCommander:
"""docstring for DAQAppController"""

def __init__(
self, console: Console, app: str, host: str, port: int, response_port: int, response_host: str = None, proxy : tuple = None
self,
console:Console,
app:str,
host:str,
port:int,
response_port:int,
response_host:str = None,
proxy:tuple = None,
connection_timeout:int = 1,
):
self.log = logging.getLogger(app)
self.console = console
Expand All @@ -221,6 +229,7 @@ def __init__(
self.proxy = proxy
self.response_queue = Queue()
self.sent_cmd = None
self.connection_timeout = connection_timeout

def __del__(self):
pass
Expand All @@ -232,11 +241,11 @@ def ping(self):

if not self.proxy:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.settimeout(self.connection_timeout)
else:
s = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
s.set_proxy(socks.SOCKS5, self.proxy[0], self.proxy[1])
s.settimeout(1)
s.settimeout(self.connection_timeout)
try:
s.connect((self.app_host, self.app_port))
s.shutdown(2)
Expand Down Expand Up @@ -269,10 +278,10 @@ def send_command(self,

ack = requests.post(
self.app_url,
data=json.dumps(cmd),
headers=headers,
timeout=1.,
proxies={
data = json.dumps(cmd),
headers = headers,
timeout = self.connection_timeout,
proxies = {
'http': f'socks5h://{self.proxy[0]}:{self.proxy[1]}',
'https': f'socks5h://{self.proxy[0]}:{self.proxy[1]}'
} if self.proxy else None
Expand Down Expand Up @@ -320,11 +329,26 @@ class AppSupervisor:
Tracks the last executed and successful commands
"""

def __init__(self, console: Console, desc: AppProcessDescriptor, listener: ResponseListener, response_host: str = None, proxy: tuple = None):
def __init__(
self,
console: Console,
desc: AppProcessDescriptor,
listener: ResponseListener,
response_host: str = None,
proxy: tuple = None,
connection_timeout:int=1,
):
self.console = console
self.desc = desc
self.commander = AppCommander(
console, desc.name, desc.host, desc.port, listener.port, response_host, proxy
console = console,
app = desc.name,
host = desc.host,
port = desc.port,
response_port = listener.port,
response_host = response_host,
proxy = proxy,
connection_timeout = connection_timeout,
)
self.last_sent_command = None
self.last_ok_command = None
Expand Down
9 changes: 8 additions & 1 deletion src/nanorc/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,14 @@ def on_enter_boot_ing(self, event) -> NoReturn:
name=n,
console=self.console,
log=self.log,
sup=AppSupervisor(self.console, d, self.listener, response_host, proxy),
sup = AppSupervisor(
console = self.console,
desc = d,
listener = self.listener,
response_host = response_host,
proxy = proxy,
connection_timeout = 10 if event.kwargs['pm'].use_k8spm() else 1,
),
parent=self,
fsm_conf=self.fsm_conf)

Expand Down

0 comments on commit 9d0a19f

Please sign in to comment.