Skip to content

Commit 69c5b6f

Browse files
committed
Add timeout and improved error handling to PostgreSQL server startup in CI workflow
1 parent e8b4beb commit 69c5b6f

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

.github/workflows/postgresql-test.yml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ jobs:
358358
id: start-server
359359
if: steps.init-database.outputs.success == 'true'
360360
continue-on-error: true
361+
timeout-minutes: 3
361362
run: |
362363
$ErrorActionPreference = "Continue"
363364
$binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
@@ -369,21 +370,44 @@ jobs:
369370
try {
370371
$pgCtlExe = Join-Path $binPath "pg_ctl.exe"
371372
372-
# Start the server
373+
# Start the server with timeout
373374
Write-Host "Starting PostgreSQL server..."
374-
$output = & $pgCtlExe -D $dataDir -l $logFile start 2>&1 | Out-String
375-
Write-Host $output
375+
$startJob = Start-Job -ScriptBlock {
376+
param($pgCtl, $data, $log)
377+
& $pgCtl -D $data -l $log -w -t 30 start 2>&1 | Out-String
378+
} -ArgumentList $pgCtlExe, $dataDir, $logFile
379+
380+
# Wait for the job with timeout
381+
$completed = Wait-Job -Job $startJob -Timeout 60
376382
377-
# Wait for server to be ready
378-
Write-Host "Waiting for server to be ready..."
379-
Start-Sleep -Seconds 5
383+
if ($completed) {
384+
$output = Receive-Job -Job $startJob
385+
Write-Host $output
386+
Remove-Job -Job $startJob -Force
387+
} else {
388+
Write-Host "⚠️ Server start timed out after 60 seconds"
389+
Stop-Job -Job $startJob
390+
Remove-Job -Job $startJob -Force
391+
}
392+
393+
# Wait a bit for server to stabilize
394+
Write-Host "Waiting for server to stabilize..."
395+
Start-Sleep -Seconds 3
380396
381397
# Check server status
398+
Write-Host "Checking server status..."
382399
$statusOutput = & $pgCtlExe -D $dataDir status 2>&1 | Out-String
383400
Write-Host $statusOutput
384401
385402
if ($statusOutput -match "server is running") {
386403
Write-Host "✅ PostgreSQL server is running"
404+
405+
# Display server log
406+
if (Test-Path $logFile) {
407+
Write-Host "Server log (last 20 lines):"
408+
Get-Content $logFile -Tail 20 | Write-Host
409+
}
410+
387411
echo "success=true" >> $env:GITHUB_OUTPUT
388412
echo "log-file=$logFile" >> $env:GITHUB_OUTPUT
389413
} else {
@@ -397,6 +421,7 @@ jobs:
397421
}
398422
} catch {
399423
Write-Host "❌ Error starting server: $_"
424+
Write-Host "Error details: $($_.Exception.Message)"
400425
if (Test-Path $logFile) {
401426
Write-Host "Server log:"
402427
Get-Content $logFile | Write-Host

0 commit comments

Comments
 (0)