zmactep / hasbolt

Haskell driver for Neo4j 3+ (BOLT protocol)
BSD 3-Clause "New" or "Revised" License
82 stars 13 forks source link

Neo4j 4 drops bolt version 1, perhaps default to higher version? #21

Closed esjmb closed 3 years ago

esjmb commented 4 years ago

I understand that neo4j 4 has dropped support for bolt version 1, which causes hasbolt connections to fail with the default version 1 requested.

Perhaps it's time to default to version 2?

I would also like to suggest that current error message be adjusted.

It presently reads "Cannot connect: unsupported server version".

I think that's misleading, and would suggest instead "Cannot connect: Requested Bolt protocol version unsupported".

thanks for the great work, Stephen.

esjmb commented 4 years ago

On further investigation, Neo4j 4.0.0.0 is only returning bolt protocols version 3 and 4.

zmactep commented 4 years ago

Hi Stephen!

Thank you for the feedback. I think you are right and it's time to move to BOLTv3. I'll make the commit with this change after several neo4j versions testing.

zmactep commented 4 years ago

The problem is deeper that I thought. BOLT v3 (and v4) is binary incompatible with BOLT v1. Also all versions except v1 are still undocumented. You may find a bit more on this problem here.

So I have to investigate neo4j sources a bit to find the differences and understand the way to make changes.

esjmb commented 4 years ago

Appreciate that - had a bit of a play with connect and could see the server failing to follow through on standard v1 type interaction following bolt protocol negotiation.

Are these the relevant sources?

https://github.com/neo4j/neo4j/tree/4.0/community/bolt/src/main/java/org/neo4j/bolt

normenmueller commented 4 years ago

I’m following this documentation but after sending the four magic bytes and the version proposal (1, 0, 0, 0) it seems like the server responses with a ‘0’. Could that be the case?

main :: IO ()
main = do
    pipe <- connect withConfig
    close pipe

withConfig :: BoltCfg
withConfig = def {user = "neo4j", password = "scratch"}

[...]
-- at `Database.Bolt.Connection.Pipe` 
handshake :: MonadPipe m => Pipe -> BoltCfg -> m ()
handshake pipe bcfg = do let conn = connection pipe
                         C.send conn (encodeStrict $ magic bcfg)
                         C.send conn (boltVersionProposal bcfg)
                         serverVersion <- decodeStrict <$> recvChunk conn 4
                         when (serverVersion /= version bcfg) $
                           throwError $ UnsupportedServerVersion (T.pack . show $ serverVersion)
                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                         flush pipe (createInit bcfg)
                         response <- fetch pipe
                         unless (isSuccess response) $
                           throwError AuthentificationFailed

executing with this minor adaptation yield

▶ stack exec scratch-exe
errata-exe: Cannot connect: server version '0' is not supported

Changing to version '4' and commenting out flushing in the handshake yields

instance Default BoltCfg where
  def = BoltCfg { magic         = 1616949271
                , version       = 4

[...]
-- at `Database.Bolt.Connection.Pipe` 
handshake :: MonadPipe m => Pipe -> BoltCfg -> m ()
handshake pipe bcfg = do let conn = connection pipe
                         C.send conn (encodeStrict $ magic bcfg)
                         C.send conn (boltVersionProposal bcfg)
                         serverVersion <- decodeStrict <$> recvChunk conn 4
                         when (serverVersion /= version bcfg) $
                           throwError $ UnsupportedServerVersion (T.pack . show $ serverVersion)
                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                         -- flush pipe (createInit bcfg)
                         -- response <- fetch pipe
                         -- unless (isSuccess response) $
                         --   throwError AuthentificationFailed

and executing those adaptations yields, at least no error

▶ stack exec scratch-exe
OscarSouth commented 3 years ago

Popping in here to link to this Issue: https://github.com/neo4j/neo4j/issues/12361

Which announces official Bolt documentation here: https://7687.org/

zmactep commented 3 years ago

Hi, everyone!

So, I've found a couple of evenings and made the initial support of protocol version 3 (not the 4). It's still lots of work, but you can use hasbolt with the latest neo4j version for now.

I want to say thanks to all who have written me e-mails with questions about the library. It's very motivating. Hope, we'll make the further work much faster.

flip111 commented 1 year ago

https://7687.org/ is down and used to go upto neo4j 4.4 https://web.archive.org/web/20221017144413/https://7687.org/

For neo4j 5.0 - 5.3 with bolt 5.0 this website seems up to date https://neo4j.com/docs/bolt/current/bolt/ because it referenced changes made to 5.0 in a few places.