Skip to content

Conversation

ali-ince
Copy link
Contributor

When a session is closed before consuming results of executed statements, we previously did not handle pending results and directly close the underlying connection - which contradicts with behaviour from other official drivers.

A sample code snippet demonstrating the use case is as follows;

func closeSessionWithoutFirstProcessingResults(driver *neo4j.Driver) (neo4j.Result, error) {
  if session, err = driver.Session(neo4j.AccessModeRead); err != nil {
    return nil, err
  }
  defer session.Close()

  return session.Run("UNWIND RANGE(1,100) AS N RETURN N", nil)
}

This PR makes session to buffer all pending results into result buffers before closing the underlying connection and makes the results available should they be used. On the contrary, in case of an explicit transaction - the transaction will eventually be rolled back if neither Commit or Rollback is called.

It is important to note that closing sessions before processing executed statement results is not a good practice and should be avoided - it may hide underlying errors which would be visible otherwise.

@ali-ince ali-ince merged commit 6ebee69 into neo4j:1.7-dev Dec 12, 2018
@ali-ince ali-ince deleted the 1.7-buffer-pending-results-on-session-close branch December 17, 2018 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants