florinpatrascu / bolt_sips

Neo4j driver for Elixir
Apache License 2.0
258 stars 49 forks source link

Consistent bad connection state after malformed query: "... You need to\n`ACK_FAILURE` or `RESET` ..." #78

Closed Tomboyo closed 4 years ago

Tomboyo commented 4 years ago

I have the following fulltext index on my database:

CALL db.index.fulltext.createNodeIndex(
  "topic_label",
  ["topic"],
  ["label"],
  { analyzer: "simple" });

And the following Bolt.Sips configuration (note the pool_size of just 1):

[
  url: "bolt://localhost:7687",
  ssl: true,
  basic_auth: [
    username: "neo4j",
    password: "[REDACTED]"
  ],
  pool_size: 1
]

If I issue the following malformed query (because badparen) is not quoted and is therefore treated like a Lucene query containing syntax errors):

Bolt.Sips.query(
  Bolt.Sips.conn(),
  "CALL db.index.fulltext.queryNodes(\"topic_label\", \"badparen)\") YIELD node RETURN node")

Then that query correctly fails with an error from Apache Lucene:

{:error,
 [
   code: nil,
   message: "run_statement: Unknown failure: {:failure, %Bolt.Sips.Internals.Error{code: \"Neo.ClientError.Procedure.ProcedureCallFailed\", connection_id: 48, function: :pull_all, message: \"Failed to invoke procedure `db.index.fulltext.queryNodes`: Caused by: org.apache.lucene.queryparser.classic.ParseException: Encountered \\\" \\\")\\\" \\\") \\\"\\\" at line 1, column 8.\\nWas expecting one of:\\n    <EOF> \\n    <AND> ...\\n    <OR> ...\\n    <NOT> ...\\n    \\\"+\\\" ...\\n    \\\"-\\\" ...\\n    <BAREOPER> ...\\n    \\\"(\\\" ...\\n    \\\"*\\\" ...\\n    \\\"^\\\" ...\\n    <QUOTED> ...\\n    <TERM> ...\\n    <FUZZY_SLOP> ...\\n    <PREFIXTERM> ...\\n    <WILDTERM> ...\\n    <REGEXPTERM> ...\\n    \\\"[\\\" ...\\n    \\\"{\\\" ...\\n    <NUMBER> ...\\n    \", type: :cypher_error}}\n"
 ]}

But! If I then try to issue any further queries:

Bolt.Sips.query(Bolt.Sips.conn(), "Match (n) return n") 

Then they fail with the following exception:

{:error,
 [
   code: nil,
   message: "The session is in a failed state and ignores further messages. You need to\n`ACK_FAILURE` or `RESET` in order to send new messages.\n"
 ]}

I wasn't sure if this was a bug or if I was missing a configuration, but it looked like the failed state error was leaking out of internals; was something supposed to ACK or RESET on my behalf? The connection seems to stay in this bad state indefinitely, which could poison a pool over time if a running system has the right bugs in it.

Thanks!

Environment

florinpatrascu commented 4 years ago

thank you for the detailed report, I'll try to reproduce it on my local. This is using one of the APOC's stored procedures, right?

Tomboyo commented 4 years ago

To my understanding, the db.index.fulltext.createNodeIndex & queryNodes procedures come standard with 3.5. I haven't intentionally installed APOC, at least, and CALL apoc.help('apoc') fails due to unknown procedure.

florinpatrascu commented 4 years ago

@Tomboyo - would you mind testing with the code from our master branch and report back your findings?! Thank you!

Tomboyo commented 4 years ago

Gladly! I'll give it a shot this evening. :)

On Fri, Jan 3, 2020, 2:27 PM Florin notifications@github.com wrote:

@Tomboyo https://github.com/Tomboyo - would you mind testing with the code from our master branch and report back your findings?! Thank you!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/florinpatrascu/bolt_sips/issues/78?email_source=notifications&email_token=AA2OQ6IVYRW2NYFWTL24YQ3Q36GTPA5CNFSM4JTES3S2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIB4RXI#issuecomment-570673373, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2OQ6OFC4CGWZ7KWRLWRATQ36GTPANCNFSM4JTES3SQ .

Tomboyo commented 4 years ago

I can confirm that this is working on master against my database. :)

florinpatrascu commented 4 years ago

I just published a new release, published to https://hex.pm/packages/bolt_sips/2.0.3, containing all the new improvements, including the fix for this issue. Please feel free to close it, if you're satisfied with the new version :)

Thank you, @Tomboyo and @kristofka!

Tomboyo commented 4 years ago

Just got around to building with the new release. Looks good there as well, going ahead and closing this. Thanks everyone!