nuodb / nuodb-python

Pure-python SQL driver implementation.
BSD 3-Clause "New" or "Revised" License
19 stars 19 forks source link

Unable to establish connection to NuoDB Docker installation #161

Closed theWolf1198 closed 3 months ago

theWolf1198 commented 1 year ago

Replication steps:

  1. Set up the NuoDB installation in the local environment by following the docs in Link

  2. Used the following code to try and connect to NuoDB:

    try: 
      options = {'schema': 'hockey'}
      self.connection = pynuodb.connect(database="test", host="localhost:8888", user="dba", password="goalie", options=options)
    except Exception as e:
      log.logger.error(f"Error while connecting to {self.database}, {e}")
  3. The connection fails with exception: Session was closed while receiving msgLength=[1213485969] len(msg)=[191] len(received)=[0]

Expected behaviour: I should be a be to establish a connection to the nuodb broker

NikTJ777 commented 1 year ago

The port in your connection params is (probably) incorrect. The default port for making a connection is 48004, and not 8888.

It is possible to override all ports, but since you are using 8888, which is the default ReST port, I am assuming that your connection port is also the default - which is 48004.

Since 48004 is the default, you could try either of the following:

Kind Regards, Nik TJ

theWolf1198 commented 1 year ago

@NikTJ777 , this is the command I used to raise the docker container for Nuo admin.

   --network nuodb-net --publish 8888:8888 \
   --volume nuoadmin-raft-1:/var/opt/nuodb \
   --env NUODB_DOMAIN_ENTRYPOINT=nuoadmin1 \
   nuodb/nuodb-ce:latest nuoadmin 

If you see, the published port is 8888, so I assume this would be the port to connect to, right? Port 48004 will not be available outside the docker net.

adriansuarez commented 1 year ago

@theWolf1198, as @NikTJ777 said, port 8888 is not the port that services SQL connection requests, but HTTP (REST) requests. There are multiple ports that the admin process listens on that use different protocols, and you cannot use HTTP to obtain a SQL connection. That is an entirely different protocol.

You will have to update the docker run command to also publish the SQL server port by adding --publish 48004:48004, in addition to updating the Python code to use port 48004 instead of 8888.

adriansuarez commented 1 year ago

@theWolf1198: By the way, after you fix the port, you will still run into issues when connecting a database that is running within Docker, because the hostname/address that is advertised for database processes within Docker is not resolvable outside of Docker.

When the SQL driver connects to the admin on port 48004 to request a connection, the admin process responds with the hostname and port of a suitable transaction engine, which the SQL driver immediately tries to connect to. That hostname would not be resolvable to the Python script that is executing outside of the Docker network.

The workaround would be to run the Python client within a Docker container attached to the same Docker network, or to use the direct=true connection property, which is what you seem to be using the PR you posted in the mindsdb repo.

madscientist commented 3 months ago

Closing. Thanks!