ec297626cd
http.Get uses http.DefaultClient, which has no timeout and carries no context. A backend that accepted the TCP connection but never responded blocked waitForHealth forever, hanging the launcher with no way to cancel it -- exactly what the suppressed noctx lint was warning about. Probe through a package-level client with an explicit 2s timeout using http.NewRequestWithContext, thread a context down from launcher.Run, and drain each response body before closing so the connection is reused across poll iterations. The overall wait now derives a deadline from the caller's context, so cancellation ends it too. Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
46 lines
998 B
Go
46 lines
998 B
Go
package launcher
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func runInstalled(ctx context.Context, opts Options) int {
|
|
backendPort, err := resolvePorts(opts)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "[kandev] "+err.Error())
|
|
return 2
|
|
}
|
|
ports, err := pickPorts(backendPort)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "[kandev] "+err.Error())
|
|
return 1
|
|
}
|
|
bundle, err := resolveRuntimeBundle()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "[kandev] "+err.Error())
|
|
return 1
|
|
}
|
|
if err := ensureDataDir(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "[kandev] "+err.Error())
|
|
return 1
|
|
}
|
|
|
|
logLevel := resolveLogLevel(opts)
|
|
releaseTag := os.Getenv("KANDEV_VERSION")
|
|
if releaseTag == "" {
|
|
releaseTag = "(" + bundle.Source + ")"
|
|
}
|
|
return launchManaged(ctx, managedAppConfig{
|
|
Header: "release: " + releaseTag,
|
|
Mode: "run",
|
|
Backend: bundle.Launcher,
|
|
BackendCWD: filepath.Dir(bundle.Launcher),
|
|
Ports: ports,
|
|
LogLevel: logLevel,
|
|
Opts: opts,
|
|
})
|
|
}
|