Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-40

connection pool issues

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 0.9.53
    • Fix Version/s: 0.9.54
    • Component/s: Generic
    • Labels:
      None

      Description

      I'm having issues using connection pools. I've only managed to get them to work when the C code allocates the connection, either via creation of the pool object (where the connect options allocates all the available pool slots) or by adding connection options via set_config() and then using add_connection() with no arg. If I try to add a connection I've made in the python code it either fails with an error or I get a segfault. So, to be clear, here's what works and what doesn't:

      Works (all connections pre-allocated):

      pool = mariadb.ConnectionPool(
          pool_name = 'pool1',
          pool_size = 3,
          host = 'localhost',
          user = 'root',
          database = 'test',
          )
      

      Works (all connections added via internal connection):

      pool = mariadb.ConnectionPool(pool_name = 'pool1')
      pool.set_config(
              pool_size = 3,
              host = 'localhost',
              user = 'root',
              database = 'test',
              )
      for j in range(3):
          pool.add_connection()
      

      Fails with an error on the first add:

      pool = mariadb.ConnectionPool(
              pool_name = 'pool1',
              pool_size = 3,
              )
      for j in range(3):
          c = mariadb.connect(
              host = 'localhost',
              user = 'root',
              database = 'test',
              )
          pool.add_connection(c)
      

      => mariadb.PoolError: Couldn't get configuration for pool 'pool1'.

      This segfaults on the first add:

      pool = mariadb.ConnectionPool(pool_name = 'pool1')
      pool.set_config(pool_size = 3)
      for j in range(3):
          c = mariadb.connect(
              host = 'localhost',
              user = 'root',
              database = 'test',
              )
          pool.add_connection(c)
      

      Here's one more failure:

      def get_a_connection(pool):
          conn = None
          while not conn:
              try:
                  conn = pool.get_connection()
                  break
              except mariadb.PoolError as e:
                  pass
              try:
                  pool.add_connection()
              except mariadb.PoolError as e:
                  print(f"Pool is full: {e}")
                  break
       
          return conn
       
      pool = mariadb.ConnectionPool(pool_name = 'pool1')
       
      pool.set_config(
          pool_size = 3,
          host = 'localhost',
          user = 'root',
          database = 'test',
          )
      for j in range(3):
          conn = get_a_connection(pool)
      

      => first add_connection() fails with:
      => TypeError: 'sqlstate' is an invalid keyword argument for this function

      These tests were done with the latest pip3 install --pre mariadb code using python 3.6.9.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              georg Georg Richter
              Reporter:
              WayneD Wayne Davison
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: