Skip to content

Commit 3593d42

Browse files
veoxpipermerriam
authored andcommitted
Workaround: wait longer for IPC socket file to appear (ethereum#1197)
* trinity/utils/ipc: increase wait_for_ipc() timeout to 10 seconds. It seems that on machines with slow I/O, creation of the socket file may take a long while. * trinity: log duration of wait for IPC file. * trinity/main: minor, move wait_for_ipc() one line down. It is the networking process that needs the socket to be present, so move the wait-for-socket line closer to starting the former. * trinity/utils/ipc: WARN on timeout reached, demote to DEBUG on success. * trinity/utils/ipc: minor, change condition from `>` to `>=`. Dummy commit to force CircleCI re-run. * Revert previous four commits - taking alrenative approach. Will reuse previous loop structure in wait_for_ipc(), and raise an exception on timeout instead. * trinity: raise exception in wait_for_ipc() on reaching timeout. The boot procedure still won't try to shut down cleanly, but will at least print an error message _and_ a warning about proceeding anyway. * Change to exit trinity if database IPC connection cannot be made.
1 parent 931e915 commit 3593d42

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

trinity/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,14 @@ def trinity_boot(args: Namespace,
194194
# start the processes
195195
database_server_process.start()
196196
logger.info("Started DB server process (pid=%d)", database_server_process.pid)
197-
wait_for_ipc(chain_config.database_ipc_path)
197+
198+
# networking process needs the IPC socket file provided by the database process
199+
try:
200+
wait_for_ipc(chain_config.database_ipc_path)
201+
except TimeoutError as e:
202+
logger.error("Timeout waiting for database to start. Exiting...")
203+
kill_process_gracefully(database_server_process, logger)
204+
sys.exit(1)
198205

199206
networking_process.start()
200207
logger.info("Started networking process (pid=%d)", networking_process.pid)

trinity/utils/ipc.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@
88
from typing import Callable
99

1010

11-
def wait_for_ipc(ipc_path: pathlib.Path, timeout: int=1) -> None:
11+
def wait_for_ipc(ipc_path: pathlib.Path, timeout: int=10) -> None:
12+
"""
13+
Waits up to ``timeout`` seconds for the IPC socket file to appear at path
14+
``ipc_path``, or raises a :exc:`TimeoutError` otherwise.
15+
"""
1216
start_at = time.time()
1317
while time.time() - start_at < timeout:
1418
if ipc_path.exists():
15-
break
16-
time.sleep(0.05)
19+
return
20+
else:
21+
time.sleep(0.05)
22+
# haven't `return`ed by now - raise unconditionally
23+
raise TimeoutError("IPC socket file has not appeared in %d seconds!" % timeout)
1724

1825

1926
DEFAULT_SIGINT_TIMEOUT = 10

0 commit comments

Comments
 (0)