neo4j/neo4j-go-driver

Getting different error when running same cypher using goroutine

hsivakum opened this issue · 1 comments

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
  • Neo4j version: Enterprise 4.1.3
  • Neo4j Mode: Single instance
  • Driver version: v1.8.3
  • Operating system: macOS BigSur
  • Steps to reproduce
  • using this neo4j-go-driver to query a collection of node value as an array with go channels

I used go channels to query the same cipher in multiple golang services, used security rules per service, and created separate user per service

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
}

`

  • Expected behavior

having this repo call as route called /interests and calling this directly from UI, another API call to XYZ service which internally making an s2s channel call to /interests as a goroutine and facing this error at random intervals. suspecting this is some kind of race condition, the expected behavior is to get data regardless of any race condition

  • Actual behavior

getting one of the errors listed below

  1. Invalid struct size: 146
  2. Invalid Handle
  3. Map key is not string type: int64
  4. Invalid struct size: 201
  5. Unconsumed data

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

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.