Skip to content

[BUG] MySQL module not closing connections/cursors #20

@lvinagre

Description

@lvinagre

Description
While using MySQL module to manage users/grants in CloudSQL (GCP), it has been noticed connections/cursors are not being closed by end of execution and are kept open until timeout occurs.

Setup
salt-master running on GCP VM instance (Debian 11)
CloudSQL MySQL instance (8.0.31-google)

Please be as specific as possible and give set-up details.

  • on-prem machine
  • VM (Virtualbox, KVM, etc. please specify)
  • VM running on a cloud service, please be explicit and add details
  • container (Kubernetes, Docker, containerd, etc. please specify)
  • or a combination, please be explicit: MySQL instance on CloudSQL (GCP)
  • jails if it is FreeBSD
  • classic packaging
  • onedir packaging
  • used bootstrap to install

Steps to Reproduce the behavior

  • Create a state to add a user and grants to that user
  • Let it run and check GCP logs afterwards (from our setup, they appear after 30~45s after):
severity: "INFO"
textPayload: "2025-05-17T01:51:33.854362Z 2365374 [Note] [MY-010914] [Server] Aborted connection 2365374 to db: 'unconnected' user: '{USER}' host: '{SOURCE IP}' (Got an error reading communication packets)."

Expected behavior
No errors/timeouts are logged after state finishes execution

Versions Report

Salt Version:
          Salt: 3006.7

Python Version:
        Python: 3.10.13 (main, Feb 19 2024, 03:31:20) [GCC 11.2.0]

Dependency Versions:
          cffi: 1.14.6
      cherrypy: 18.6.1
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: 4.0.11
     gitpython: 3.1.41
        Jinja2: 3.1.3
       libgit2: Not Installed
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 23.2.0
        relenv: 0.15.1
         smmap: 5.0.1
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: debian 11 bullseye
        locale: utf-8
       machine: x86_64
       release: 5.10.0-25-cloud-amd64
        system: Linux
       version: Debian GNU/Linux 11 bullseye

Additional context
Looking at the module's code, I do not see any connection or cursor being handled using python's with nor being closed after being opened/used. Not sure if this was deemed not necessary, but I would say it is nice to have it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions