我在码头部署了DgraphAlpha和DgraphZero。如文档中所述,我正在连接到Dgraph。
func newClient() *dgo.Dgraph {
d, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
return dgo.NewDgraphClient(
api.NewDgraphClient(d),
)
}成功地创建了客户端,但是当我试图搜索
txn := i.dgraphClient.NewReadOnlyTxn()
defer txn.Discard(context.Background())
dgraphQuery := "search here"
response, err := txn.Query(context.Background(), dgraphQuery)
if err != nil {
// error here
}我收到一个错误:
rpc error: code = Unavailable desc = connection closed before server preface received这个错误并不总是发生在意想不到的时刻,因此我很难确定它的根源。有人遇到过类似的事情吗?有什么问题吗?
发布于 2022-10-10 12:53:17
除了其他临时原因之外,造成此错误的一个常见原因是启用了TLS的服务器和试图不使用TLS进行连接的客户端。
确保在客户端上正确配置了TLS选项:
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{myCertificate},
RootCAs: myCAPool,
}
tlsOpt := grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))
conn, err := grpc.DialContext(ctx, "<connection_string>", tlsOpt)还要确保在客户端连接上实际使用客户端证书。
发布于 2022-03-26 12:35:22
这可能是时间的问题。在最初的请求中,这种情况可能会发生得更频繁?你在DGraph方面有什么日志吗?
考虑:
不建议使用:使用WithTransportCredentials和insecure.NewCredentials()代替。
关于错误:
https://grpc.github.io/grpc/core/md_doc_statuscodes.html
状态代码14
这似乎是一个短暂的错误。
过一段时间你可以再试一次。在这种情况下可以使用一些检索器,例如:
https://stackoverflow.com/questions/71627962
复制相似问题