{"record":{"id":"ea81b18f83cea2e0","repo":"amir20/dozzle","slug":"failed-to-connect-to-s-w","errorCode":null,"errorMessage":"failed to connect to %s: %w","messagePattern":"failed to connect to (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/client.go","lineNumber":72,"sourceCode":"\t\tRootCAs:            caCertPool,\n\t\tInsecureSkipVerify: true, // Set to true if the server's hostname does not match the certificate\n\t}\n\n\t// Create the gRPC transport credentials\n\tcreds := credentials.NewTLS(tlsConfig)\n\n\topts = append(opts,\n\t\tgrpc.WithTransportCredentials(creds),\n\t\tgrpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(10*1024*1024), grpc.UseCompressor(gzip.Name)),\n\t\tgrpc.WithKeepaliveParams(keepalive.ClientParameters{\n\t\t\tTime:                30 * time.Second,\n\t\t\tTimeout:             10 * time.Second,\n\t\t\tPermitWithoutStream: true,\n\t\t}),\n\t)\n\tconn, err := grpc.NewClient(endpoint, opts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to connect to %s: %w\", endpoint, err)\n\t}\n\n\tclient := pb.NewAgentServiceClient(conn)\n\n\treturn &Client{\n\t\tclient:       client,\n\t\tconn:         conn,\n\t\tendpoint:     endpoint,\n\t\tnameOverride: nameOverride,\n\t\tgroup:        group,\n\t}, nil\n}\n\n// ParseEndpoint splits an agent endpoint of the form \"address|name|group\" into\n// its parts. Name and group are optional; address is required.\nfunc ParseEndpoint(endpoint string) (string, string, string, error) {\n\tparts := strings.Split(endpoint, \"|\")\n\tif len(parts) > 3 || parts[0] == \"\" {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/agent/client.go#L54-L90","documentation":"NewClient wraps the error from grpc.NewClient as \"failed to connect to %s: %w\" when the client connection cannot even be created for the endpoint. Note grpc.NewClient is lazy, so this is almost always an invalid target string (bad scheme/address) rather than the agent being down; runtime connectivity failures surface later through rpcErrToErr.","triggerScenarios":"agent.NewClient(endpoint, certs) where the parsed address is malformed for gRPC's resolver, e.g. missing host:port, an unsupported scheme prefix, or empty after parsing \"|name|group\"-style endpoints.","commonSituations":"Docker label/env configured endpoint like \"192.168.1.5\" without port instead of \"192.168.1.5:7007\"; DNS names with typos; IPv6 addresses not bracketed; accidentally leaving the DOZZLE_AGENT address as a URL (https://host:7007).","solutions":["Fix the endpoint to host:port form (default agent port 7007), e.g. \"agent-host:7007\" or \"host|Friendly Name\"","Drop any URL scheme (no https://) and bracket IPv6 addresses like [fd00::1]:7007","Verify the endpoint string comes from the DOZZLE_AGENT config/labels without extra characters (spaces, quotes)","If the agent is unreachable at runtime, check the agent container is up and port 7007 is published; the error appears on first RPC"],"exampleFix":"// before\nclient, _ := agent.NewClient(\"https://agent:7007|Agent\", certs)\n// after\nclient, err := agent.NewClient(\"agent:7007|Agent\", certs)\nif err != nil { log.Fatal().Err(err).Msg(\"agent endpoint invalid\") }","handlingStrategy":"validation","validationCode":"if _, _, _, err := agent.ParseEndpoint(endpoint); err != nil { return err }\nhost, port, ok := strings.Cut(endpoint, \"|\")\nif !strings.Contains(host, \":\") { return fmt.Errorf(\"endpoint %q must be host:port\", endpoint) }","typeGuard":"func validEndpoint(e string) bool { addr, _, _, err := agent.ParseEndpoint(e); return err == nil && strings.Contains(addr, \":\") }","tryCatchPattern":"client, err := agent.NewClient(endpoint, certs)\nif err != nil {\n    return fmt.Errorf(\"agent %s unreachable, check address and port 7007: %w\", endpoint, err)\n}","preventionTips":["Always configure endpoints as host:port (agent default port 7007), never URLs with schemes","Validate endpoints with agent.ParseEndpoint at config load and fail fast","Check agent container is running and port 7007 is published before connecting"],"tags":["go","grpc","network","agent","configuration"],"backgroundTag":"connection-refused","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}