johnnadratowski / golang-neo4j-bolt-driver

Golang Bolt driver for Neo4j
MIT License
213 stars 72 forks source link

Couldn't read expected bytes for message length. Read: 0 Expected: 2. Internal Error(*errors.errorString):driver: bad connection #51

Closed MrDHat closed 6 years ago

MrDHat commented 6 years ago

I get this error whenever I am trying to query something from the db:

Couldn't read expected bytes for message length. Read: 0 Expected: 2. Internal Error(*errors.errorString):driver: bad connection

My code worked fine until a couple of hours back. Nothing changed in my setup or code. PreparePipeline, ExecPipeline etc work fine and do not throw any errors. I am using neo4j with docker fwiw. Here is a sample test which is failing:

// Query executes a cypher query
func Query(cypher string, params map[string]interface{}) ([]interface{}, error) {
    conn, err := instance.GetNeoPool()
    if err != nil {
        return nil, err
    }
    stmt, err := conn.PrepareNeo(cypher)
    if err != nil {
        return nil, err
    }

    rows, err := stmt.QueryNeo(params)
    if err != nil {
        return nil, err
    }
    var res []interface{}
    for err == nil {
        row, _, err := rows.NextNeo()
        if err != nil && err != io.EOF {
            return nil, err
        } else if err != io.EOF {
            res = append(res, row)
        }
    }
    stmt.Close()

    return res, nil
}
func TestQuery(t *testing.T) {
    Convey("Given a cypher", t, func() {
        cypher := "MATCH (n) RETURN n LIMIT {limit}"
        params := map[string]interface{}{
            "limit": 25,
        }

        Convey("it should execute the commands without any errors", func() {
            res, err := Query(cypher, params)
            So(err, ShouldBeNil)
            So(res, ShouldNotBeNil)
        })
    })
}
MrDHat commented 6 years ago

I changed the implementation a bit and changed row, _, err := rows.NextNeo() to

var row interface{}
row, _, err = rows.NextNeo()

and it has stopped throwing that error. Any idea why?

MrDHat commented 6 years ago

Anything here? I am facing this issue in production now even after the change mentioned above.

scott-wilson commented 6 years ago

@MrDHat Are you still having troubles with this? I can take a stab at trying to understand what's going on, but can make no promises. If you are having troubles, then mind doing me a huge favour, and could you send a test file that I can directly run?

MrDHat commented 6 years ago

I am not facing this issue anymore. AFAIR, the issue was with the wrong password being supplied.

Rainshyabc commented 5 years ago

Could you tell me how to solve this problem? My password is right.