neo4j / neo4j-go-driver

Neo4j Bolt Driver for Go
Apache License 2.0
488 stars 68 forks source link

Getting different error when running same cypher using goroutine #195

Closed hsivakum closed 3 years ago

hsivakum commented 3 years ago

Facing different errors while running a cypher to get an array of values from a collection of nodes running the same cypher in goroutine from s2s API channel, and calling from UI

  1. calling X endpoint of ServiceOne to get an array of interests
  2. calling Y endpoint of ServiceTwo to get some values and calling X endpoint of ServiceOne via S2S channel as goroutine for some other operations

Code Snippet ` result, err := repository.db.Run("match (person:Person{userId: $userId})-[follows:FOLLOWS]->(interest:Interest) return COLLECT(interest.name) as interests", map[string]interface{}{ "userId": userId, })

if err != nil {
    return nil, err
}

_, err = result.Summary()

if err != nil {
    return nil, err
}

`

the error returned by neo4j go driver image

Tried solutions as of now:

  1. I'm new to neo4j, I tried increasing the memory configuration in the conf file, but that doesn't work, initially encountered this error in the neo4j docker container, to verify this tried in the neo4j desktop version but ended up in the same error
  2. tried removing the goroutine and tested, this time the frequency of error is reduced somehow but still facing the same issue though
  3. working fine in v4.2.3, facing this issue on 1.x
2hdddg commented 3 years ago

Hi @hsivakum This looks like you are accessing the same session/result/transaction instance from multiple Go routines. Only the driver "object" is safe to use from multiple Go routines. This applies to both 1.8 and 4.x branches and is by design. You should only keep instances of the driver object, all other type of objects should be kept local to the current thread.

Please use the 4.2.3 version of the driver instead of the 1.8 one, there is no reason to use the older one in terms of database server compatibility.

If you still have problems with the 4.2.3 version please open another issue with more example of how you use the driver.