Skip to content

Commit

Permalink
added back the API auto login after server restart (#2256)
Browse files Browse the repository at this point in the history
* added back the API auto login after server restart.

* rolled back the overseer change.
  • Loading branch information
yhwen authored Jan 5, 2024
1 parent 28d5bf1 commit f66a4f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions nvflare/fuel/hci/client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,12 @@ def execute(self, **kwargs):


class _Operate(State):
def __init__(self, api, sess_check_interval):
def __init__(self, api, sess_check_interval, auto_login_delay):
State.__init__(self, _STATE_NAME_OPERATE)
self.api = api
self.last_sess_check_time = None
self.sess_check_interval = sess_check_interval
self.auto_login_delay = auto_login_delay

def enter(self):
self.api.server_sess_active = True
Expand All @@ -273,6 +274,7 @@ def execute(self, **kwargs):

if new_host != cur_host or new_port != cur_port or cur_ssid != new_ssid:
# need to re-login
time.sleep(self.auto_login_delay)
api.fire_session_event(EventType.SP_ADDR_CHANGED, f"Server address changed to {new_host}:{new_port}")
return _STATE_NAME_LOGIN

Expand Down Expand Up @@ -310,6 +312,7 @@ def __init__(
debug: bool = False,
session_timeout_interval=None,
session_status_check_interval=None,
auto_login_delay: int = 5,
auto_login_max_tries: int = 5,
event_handlers=None,
):
Expand Down Expand Up @@ -418,11 +421,13 @@ def __init__(
# create the FSM for session monitoring
if auto_login_max_tries < 0 or auto_login_max_tries > MAX_AUTO_LOGIN_TRIES:
raise ValueError(f"auto_login_max_tries is out of range: [0, {MAX_AUTO_LOGIN_TRIES}]")
if auto_login_delay < 5.0:
raise ValueError(f"auto_login_delay must be more than 5.0. Got value: {auto_login_delay}]")
self.auto_login_max_tries = auto_login_max_tries
fsm = FSM("session monitor")
fsm.add_state(_WaitForServerAddress(self))
fsm.add_state(_TryLogin(self))
fsm.add_state(_Operate(self, session_status_check_interval))
fsm.add_state(_Operate(self, session_status_check_interval, auto_login_delay))
self.fsm = fsm

self.session_timeout_interval = session_timeout_interval
Expand Down
2 changes: 1 addition & 1 deletion nvflare/private/fed/server/training_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def restart(self, conn: Connection, args: List[str]):

# ask the admin client to shut down since its current session will become invalid after
# the server is restarted.
conn.append_shutdown("Goodbye!")
# conn.append_shutdown("Goodbye!")
elif target_type == self.TARGET_TYPE_CLIENT:
clients = conn.get_prop(self.TARGET_CLIENT_TOKENS)
if not clients:
Expand Down

0 comments on commit f66a4f6

Please sign in to comment.