Skip to content

Commit

Permalink
Follow up #501 and #511 with minor fixes (#513)
Browse files Browse the repository at this point in the history
- In `hivemind.Server`, use the graceful shutdown for `ConnectionHandler`
- In `hivemind.P2P`, if we are the first peer, skip checking if the provided identity is free

(cherry picked from commit 13cdd13)
  • Loading branch information
borzunov authored and mryab committed Oct 19, 2022
1 parent 090de06 commit 14de6c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
14 changes: 5 additions & 9 deletions hivemind/moe/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,8 @@ def run(self):
if self.checkpoint_saver is not None:
self.checkpoint_saver.start()

for process in self.conn_handlers:
if not process.is_alive():
process.start()
process.ready.result()
for handler in self.conn_handlers:
handler.run_in_background()

try:
self.runtime.run()
Expand Down Expand Up @@ -287,9 +285,8 @@ def shutdown(self):
"""
self.ready.clear()

for process in self.conn_handlers:
process.terminate()
process.join()
for handler in self.conn_handlers:
handler.shutdown()
logger.debug("Connection handlers terminated")

if self.module_backends:
Expand All @@ -301,11 +298,10 @@ def shutdown(self):
self.checkpoint_saver.join()

self.dht.shutdown()
self.dht.join()

logger.debug(f"Shutting down runtime")

self.runtime.shutdown()

logger.info("Server shutdown succesfully")


Expand Down
5 changes: 3 additions & 2 deletions hivemind/p2p/p2p_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ async def create(
:param quic: Deprecated, has no effect since libp2p 0.17.0
:param use_relay_hop: Deprecated, has no effect since libp2p 0.17.0
:param use_relay_discovery: Deprecated, has no effect since libp2p 0.17.0
:param check_if_identity_free: If enabled (default) and ``identity_path`` is provided,
:param check_if_identity_free: If enabled (default), ``identity_path`` is provided,
and we are connecting to an existing swarm,
ensure that this identity is not used by other peers already.
This slows down ``P2P.create()`` but protects from unintuitive libp2p errors
appearing in case of the identity collision.
Expand Down Expand Up @@ -176,7 +177,7 @@ async def create(

if identity_path is not None:
if os.path.isfile(identity_path):
if check_if_identity_free:
if check_if_identity_free and need_bootstrap:
logger.info(f"Checking that identity from `{identity_path}` is not used by other peers")
if await cls.is_identity_taken(
identity_path,
Expand Down
3 changes: 0 additions & 3 deletions tests/test_start_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ def test_cli_run_server_identity_path():
encoding="utf-8",
)

line = server_2_proc.stderr.readline()
assert re.search(r"Checking that identity.+is not used by other peers", line) is not None

line = server_2_proc.stderr.readline()
addrs_pattern_result = re.search(pattern, line)
assert addrs_pattern_result is not None, line
Expand Down

0 comments on commit 14de6c5

Please sign in to comment.