hyperledger/fabric · error

failed connecting to discovery service

Error message

failed connecting to discovery service

What it means

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.

Source

Thrown at discovery/client/client.go:174

}

// Send sends the request and returns the response, or error on failure
func (c *Client) Send(ctx context.Context, req *Request, auth *discovery.AuthInfo) (Response, error) {
	reqToBeSent := proto.Clone(req.Request).(*discovery.Request)
	reqToBeSent.Authentication = auth
	payload, err := proto.Marshal(reqToBeSent)
	if err != nil {
		return nil, errors.Wrap(err, "failed marshaling Request to bytes")
	}

	sig, err := c.signRequest(payload)
	if err != nil {
		return nil, errors.Wrap(err, "failed signing Request")
	}

	conn, err := c.createConnection()
	if err != nil {
		return nil, errors.Wrap(err, "failed connecting to discovery service")
	}

	cl := discovery.NewDiscoveryClient(conn)
	resp, err := cl.Discover(ctx, &discovery.SignedRequest{
		Payload:   payload,
		Signature: sig,
	})
	if err != nil {
		return nil, errors.Wrap(err, "discovery service refused our Request")
	}
	if n := len(resp.Results); n != req.lastIndex {
		return nil, errors.Errorf("Sent %d queries but received %d responses back", req.lastIndex, n)
	}
	return req.computeResponse(resp)
}

type resultOrError any

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Verify the peer's discovery endpoint host:port is correct and reachable (nc/curl the host:port)
  2. If the peer runs TLS, supply tlsConfig with the correct CA certificate pool and ServerName override
  3. Check DNS/container networking so the hostname in the endpoint resolves from the client
  4. Confirm the peer has discovery.enabled=true and the port matches peers.<peer>.listenAddress/discovery port

Example fix

// before: no TLS config against a TLS-enabled peer
client, _ := discovery.NewClient("peer:7051", signer, nil, dialOpts)

// after: provide TLS config
client, _ := discovery.NewClient("peer:7051", signer, &tls.Config{RootCAs: caPool, ServerName: "peer0.org1.example.com"}, dialOpts)
Defensive patterns

Strategy: retry

Validate before calling

conn, err := grpc.Dial(addr, grpc.WithBlock(), grpc.WithTimeout(5*time.Second), creds...)
if err != nil {
    return fmt.Errorf("endpoint %s unreachable: %w", addr, err)
}

Try / catch

resp, err := client.Send(ctx, req, auth)
if err != nil && strings.Contains(err.Error(), "failed connecting to discovery service") {
    // check TLS config/endpoint, then retry with backoff
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/c3d8db3e6ee8a00c. Report an issue: GitHub.