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:
@@ -55,6 +55,30 @@ func (c *Client) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
// DialWait is Dial with patience: it retries with capped backoff until the
|
||||
// socket is reachable or timeout elapses. Core loads models on boot and may
|
||||
// come up after its modules (compose depends_on orders container start, not
|
||||
// socket readiness), so a module that Dial'd once would crash-loop on a cold
|
||||
// start. Every core-dialing module should use this instead of Dial. Mid-life
|
||||
// core restarts are handled separately by the Client's own redial-on-drop.
|
||||
func DialWait(path string, timeout time.Duration) (*Client, error) {
|
||||
deadline := time.Now().Add(timeout)
|
||||
delay := 200 * time.Millisecond
|
||||
for {
|
||||
c, err := Dial(path)
|
||||
if err == nil {
|
||||
return c, nil
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
return nil, err
|
||||
}
|
||||
time.Sleep(delay)
|
||||
if delay < 2*time.Second {
|
||||
delay *= 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// call — the single request/response engine. Serialized by c.mu so a frame
|
||||
// and its reply always pair up; no interleaving to disambiguate. A wire
|
||||
// RpcError is rehydrated into the matching package sentinel (errors.Is works
|
||||
|
||||
Reference in New Issue
Block a user