Skip to content

Commit

Permalink
Fail if local Postgres cluster fails to start
Browse files Browse the repository at this point in the history
It was a while since the last time I used my linux box to develop
EdgeDB. Since then we've upgraded Postgres to 14.2 from 13. My
`localdev` directory was created by Postgres 13, so naturally
Postgres 14 wouldn't start with it.

`edb server`, however, was silently hanging without printing any error
messages. Fix this by actively checking if the Postgres process is still
alive while trying to establish the first connection to the cluster.

Once this was fixed, the following (expected) messages appeared in our
stderr:

  CRITICAL postgres: database files are incompatible with server
  INFO postgres: The data directory was initialized by PostgreSQL
       version 13, which is not compatible with this version 14.2.
  • Loading branch information
1st1 authored and elprans committed Apr 16, 2022
1 parent fb9be56 commit 3520857
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions edb/server/pgcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import shlex
import shutil
import textwrap
import time
import urllib.parse

import asyncpg
Expand Down Expand Up @@ -664,7 +663,19 @@ async def _test_connection(self, timeout: int = 60) -> str:
try:
conn_addr = self._get_connection_addr()
except PostgresPidFileNotReadyError:
time.sleep(sleep_time)
try:
assert self._daemon_process is not None
code = await asyncio.wait_for(
self._daemon_process.wait(),
sleep_time
)
except asyncio.TimeoutError:
# means that the postgres process is still alive
pass
else:
# the postgres process has exited prematurely
raise ClusterError(f"The backend exited with {code}")

continue

try:
Expand All @@ -681,7 +692,7 @@ async def _test_connection(self, timeout: int = 60) -> str:
asyncpg.CannotConnectNowError,
asyncpg.PostgresConnectionError,
):
time.sleep(sleep_time)
await asyncio.sleep(sleep_time)
continue
except asyncpg.PostgresError:
# Any other error other than ServerNotReadyError or
Expand Down

0 comments on commit 3520857

Please sign in to comment.