ipc: promote startup socket-wait to a shared DialWait; use in all modules

The cold-start crash-loop wasn't mavweb-specific — mavpoll and mavcaldav also
ipc.Dial + exit on failure, so they crash-looped until core booted too. Moved
the retry into ipc.DialWait (capped backoff, bounded) and switched mavweb,
mavpoll, mavcaldav to it. mavweb's local dialCoreWithRetry is gone.

Test: server appears after DialWait starts → it waits and connects.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
kami
2026-07-04 00:17:10 +04:00
parent a38e733514
commit 7683a9b32c
5 changed files with 67 additions and 33 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ func run(args []string) error {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
core, err := ipc.Dial(*socket)
core, err := ipc.DialWait(*socket, 60*time.Second)
if err != nil {
return err
}
+1 -1
View File
@@ -69,7 +69,7 @@ func run(args []string) error {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
core, err := ipc.Dial(*socket)
core, err := ipc.DialWait(*socket, 60*time.Second)
if err != nil {
return err
}
+1 -31
View File
@@ -87,7 +87,7 @@ func main() {
var core ipc.CoreAPI
if *coreSock != "" {
c, err := dialCoreWithRetry(*coreSock, 60*time.Second)
c, err := ipc.DialWait(*coreSock, 60*time.Second)
if err != nil {
log.Fatalf("dial core %s: %v", *coreSock, err)
}
@@ -169,36 +169,6 @@ func main() {
}
}
// dialCoreWithRetry waits for core's IPC socket to appear before giving up.
// Core loads models on boot and (esp. under compose) may come up after mavweb;
// depends_on only orders container start, not socket readiness. Retrying with
// capped backoff up to timeout stops mavweb crash-looping on a cold start. A
// core still absent past the deadline is genuinely fatal. Mid-life core
// restarts are handled separately by ipc.Client's redial-on-drop.
func dialCoreWithRetry(path string, timeout time.Duration) (*ipc.Client, error) {
deadline := time.Now().Add(timeout)
delay := 200 * time.Millisecond
for attempt := 1; ; attempt++ {
c, err := ipc.Dial(path)
if err == nil {
if attempt > 1 {
log.Printf("core socket %s ready after %d attempts", path, attempt)
}
return c, nil
}
if time.Now().After(deadline) {
return nil, err
}
if attempt == 1 {
log.Printf("waiting for core socket %s ...", path)
}
time.Sleep(delay)
if delay < 2*time.Second {
delay *= 2
}
}
}
func handleWS(w http.ResponseWriter, r *http.Request, voiceAddr string) {
conn, err := websocket.Accept(w, r, &websocket.AcceptOptions{
OriginPatterns: []string{"*"},