Skip to content

Commit 070b9bd

Browse files
authored
fix: add retry logic to supabase-start script for improved reliability (#523)
# Add retry logic to Supabase startup script This PR improves the reliability of the Supabase startup process by implementing retry logic in the `supabase-start.sh` script. The changes: - Add a 2-second delay after stopping Supabase to ensure ports are fully released - Implement up to 3 retry attempts when starting Supabase - Add a 5-second delay between retry attempts - Improve error messaging to show which attempt is currently running - Provide a more informative failure message when all retry attempts are exhausted This helps address transient port binding issues and Docker race conditions that occasionally cause startup failures.
1 parent 00921ca commit 070b9bd

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

scripts/supabase-start.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,29 @@ fi
148148
echo -e "${YELLOW}Cleaning up any stale containers...${NC}"
149149
pnpm exec supabase stop --no-backup 2>/dev/null || true
150150

151-
# Start Supabase with all configured services
152-
echo -e "${YELLOW}Starting Supabase...${NC}"
153-
if pnpm exec supabase start; then
154-
echo -e "${GREEN}✓ Supabase started successfully${NC}"
155-
exit 0
156-
else
157-
echo -e "${RED}✗ Failed to start Supabase${NC}" >&2
158-
exit 1
159-
fi
151+
# Wait for ports to be released after stop
152+
# Docker/kernel may hold ports in TIME_WAIT state briefly
153+
sleep 2
154+
155+
# Start Supabase with retry logic
156+
# Retries help with transient port binding issues and Docker race conditions
157+
MAX_ATTEMPTS=3
158+
RETRY_DELAY=5
159+
160+
for attempt in $(seq 1 $MAX_ATTEMPTS); do
161+
echo -e "${YELLOW}Starting Supabase (attempt $attempt/$MAX_ATTEMPTS)...${NC}"
162+
163+
if pnpm exec supabase start; then
164+
echo -e "${GREEN}✓ Supabase started successfully${NC}"
165+
exit 0
166+
fi
167+
168+
if [ $attempt -lt $MAX_ATTEMPTS ]; then
169+
echo -e "${YELLOW}Start failed, cleaning up and retrying in ${RETRY_DELAY}s...${NC}"
170+
pnpm exec supabase stop --no-backup 2>/dev/null || true
171+
sleep $RETRY_DELAY
172+
fi
173+
done
174+
175+
echo -e "${RED}✗ Failed to start Supabase after $MAX_ATTEMPTS attempts${NC}" >&2
176+
exit 1

0 commit comments

Comments
 (0)