Skip to content

Commit 111aaf7

Browse files
committed
fix: make service ready timeout configurable via env var
The DefaultServiceTimeout constant is hard-coded to 5 seconds, which causes the inspect-server (and occasionally other services) to be killed by the supervisor before they finish initialising on slow or resource-constrained environments such as fly.io. Replace the constant with a package-level var that reads CARTESI_SERVICE_READY_TIMEOUT from the environment at process start. The value must be a valid Go duration string (e.g. "30s", "1m"). If the variable is absent or invalid the original 5-second default is preserved, so the change is fully backward-compatible. Tested on fly.io: inspect-server takes ~21 s to become ready; with CARTESI_SERVICE_READY_TIMEOUT=30s all services report ready and the node runs normally.
1 parent 0e65d06 commit 111aaf7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

internal/services/supervisor.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@ import (
77
"context"
88
"errors"
99
"log/slog"
10+
"os"
1011
"time"
1112

1213
"golang.org/x/sync/errgroup"
1314
)
1415

15-
const DefaultServiceTimeout = 5 * time.Second
16+
// DefaultServiceTimeout is the fallback used when ReadyTimeout or StopTimeout
17+
// is not set on a SupervisorService. It defaults to 5 seconds but can be
18+
// overridden by setting the CARTESI_SERVICE_READY_TIMEOUT environment variable
19+
// before starting the node (e.g. CARTESI_SERVICE_READY_TIMEOUT=30s).
20+
// This is useful on platforms where services take longer to initialise than
21+
// the 5-second default allows (e.g. fly.io).
22+
var DefaultServiceTimeout = func() time.Duration {
23+
if v := os.Getenv("CARTESI_SERVICE_READY_TIMEOUT"); v != "" {
24+
if d, err := time.ParseDuration(v); err == nil && d > 0 {
25+
return d
26+
}
27+
}
28+
return 5 * time.Second
29+
}()
1630

1731
var (
1832
ServiceTimeoutError = errors.New("timed out waiting for service to be ready")

0 commit comments

Comments
 (0)