# Dgraph error: How to solve "Connection closed before server preface received"?

**URL:** <https://discuss.dgraph.io/t/dgraph-error-how-to-solve-connection-closed-before-server-preface-received/17167>\
**Category:** Dgraph\
**Tags:** kind:question, dgraph, kind:bug\
**Created:** [April 15, 2022, 9:16am UTC](https://discuss.dgraph.io/t/dgraph-error-how-to-solve-connection-closed-before-server-preface-received/17167 "2022-04-15T09:16:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devid](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/devid/32/9848_2.png) [@Devid](https://discuss.dgraph.io/u/Devid)\
**Post date:** [April 15, 2022, 9:16am UTC](https://discuss.dgraph.io/t/dgraph-error-how-to-solve-connection-closed-before-server-preface-received/17167/1 "2022-04-15T09:16:22Z")

</div>

I deployed DgraphAlpha and DgraphZero in docker. I am connecting to Dgraph as described in the documentation.

```auto
func newClient() *dgo.Dgraph {
    d, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
    if err != nil {
        log.Fatal(err)
    }

    return dgo.NewDgraphClient(
        api.NewDgraphClient(d),
    )
}

```

And the client is created successfully, but when I try to search

```auto
txn := i.dgraphClient.NewReadOnlyTxn()
defer txn.Discard(context.Background())

dgraphQuery := "search here"

response, err := txn.Query(context.Background(), dgraphQuery)
if err != nil {
    // error here
}

```

I get an error:  
`rpc error: code = Unavailable desc = connection closed before server preface received`

This error does not always occur, at unexpected moments, and because of this it is difficult for me to determine its root. Has anyone encountered something similar? What could be the problem?
