{"record":{"id":"c3d8db3e6ee8a00c","repo":"hyperledger/fabric","slug":"failed-connecting-to-discovery-service","errorCode":null,"errorMessage":"failed connecting to discovery service","messagePattern":"failed connecting to discovery service","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"discovery/client/client.go","lineNumber":174,"sourceCode":"}\n\n// Send sends the request and returns the response, or error on failure\nfunc (c *Client) Send(ctx context.Context, req *Request, auth *discovery.AuthInfo) (Response, error) {\n\treqToBeSent := proto.Clone(req.Request).(*discovery.Request)\n\treqToBeSent.Authentication = auth\n\tpayload, err := proto.Marshal(reqToBeSent)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed marshaling Request to bytes\")\n\t}\n\n\tsig, err := c.signRequest(payload)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed signing Request\")\n\t}\n\n\tconn, err := c.createConnection()\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed connecting to discovery service\")\n\t}\n\n\tcl := discovery.NewDiscoveryClient(conn)\n\tresp, err := cl.Discover(ctx, &discovery.SignedRequest{\n\t\tPayload:   payload,\n\t\tSignature: sig,\n\t})\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"discovery service refused our Request\")\n\t}\n\tif n := len(resp.Results); n != req.lastIndex {\n\t\treturn nil, errors.Errorf(\"Sent %d queries but received %d responses back\", req.lastIndex, n)\n\t}\n\treturn req.computeResponse(resp)\n}\n\ntype resultOrError any\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/discovery/client/client.go#L156-L192","documentation":"Client.Send in discovery/client/client.go:174 calls createConnection to dial the discovery service endpoint. If the gRPC connection cannot be established, the error is wrapped with 'failed connecting to discovery service'. This is a network/TLS-level failure between client and peer.","triggerScenarios":"createConnection fails because the discovery service endpoint is unreachable, DNS resolution fails, the port is wrong, or the TLS handshake fails (bad/incomplete CA certs, missing server name override).","commonSituations":"Peer down or behind firewall; wrong discovery endpoint in config; TLS enabled on peer but client configured without tlsConfig / missing root CAs; Kubernetes/Docker networking name mismatch; TestUnableToConnect-style unit scenarios.","solutions":["Verify the peer's discovery endpoint host:port is correct and reachable (nc/curl the host:port)","If the peer runs TLS, supply tlsConfig with the correct CA certificate pool and ServerName override","Check DNS/container networking so the hostname in the endpoint resolves from the client","Confirm the peer has discovery.enabled=true and the port matches peers.<peer>.listenAddress/discovery port"],"exampleFix":"// before: no TLS config against a TLS-enabled peer\nclient, _ := discovery.NewClient(\"peer:7051\", signer, nil, dialOpts)\n\n// after: provide TLS config\nclient, _ := discovery.NewClient(\"peer:7051\", signer, &tls.Config{RootCAs: caPool, ServerName: \"peer0.org1.example.com\"}, dialOpts)","handlingStrategy":"retry","validationCode":"conn, err := grpc.Dial(addr, grpc.WithBlock(), grpc.WithTimeout(5*time.Second), creds...)\nif err != nil {\n    return fmt.Errorf(\"endpoint %s unreachable: %w\", addr, err)\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.Send(ctx, req, auth)\nif err != nil && strings.Contains(err.Error(), \"failed connecting to discovery service\") {\n    // check TLS config/endpoint, then retry with backoff\n}","preventionTips":["Pre-check endpoint reachability (TCP dial) before creating the discovery client","Supply tls.Config with correct RootCAs and ServerName for TLS peers","Verify container/DNS names resolve from the client host"],"tags":["hyperledger-fabric","discovery-client","network","grpc","tls"],"backgroundTag":"grpc-connection-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}