Recommended Free Tools
If MySQL Connector/Python pooled sockets appear to stay open when your app shuts down, first distinguish a returned connection from a closed socket. Calling PooledMySQLConnection.close() returns that connection to the pool for reuse; it does not close the underlying connection. The documented MySQLConnectionPool API examined here does not list a pool-wide close or dispose method, so per-connection close() is not a documented way to drain every pooled socket.
Why does connection.close() leave a pooled socket open?
Connector/Python uses PooledMySQLConnection objects for connections obtained from its built-in pool. Oracle’s MySQL Connector/Python Developer Guide explains that calling close() on a pooled connection returns it to the pool and makes it available for later requests. In other words, close() releases a checked-out connection; it does not tear down the socket.
As an Amazon Associate I earn from qualifying purchases.
This behavior is intentional for reuse. It also means two separate lifecycle actions are involved: returning each borrowed connection after use and disposing of the pool and its underlying connections. The documented API provides the former behavior, but the current MySQLConnectionPool API reference does not list a public pool-wide close() or dispose() method.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteWhat to do before app termination
Identify the pool and the sockets
Confirm whether the application creates a pool through mysql.connector.connect(pool_name=..., pool_size=...) or constructs an explicit MySQLConnectionPool. Also establish that the sockets you see belong to this process rather than another application or service. An idle connection still managed by a live pool is different from a connection that the application failed to return.
#1 Best Overall
Release borrowed connections after work
Close cursors when their work is complete, then call close() on every checked-out pooled connection. For a pooled connection, that call returns it to the pool; it is not a socket-shutdown command. Use the documented lifecycle behavior rather than assuming that closing a borrowed connection drains the pool.
Do not call an undocumented pool method
The current API reference lists pool construction, add_connection(), get_connection(), set_config() and the pool_name property, but no pool-wide disposal entry. Avoid adding pool.close() as a proposed fix unless the official documentation for the exact Connector/Python version in deployment documents that method. Directly changing private connector attributes is not a supported substitute.
Rank #2
What if the requirement is to close every socket?
If shutdown requires an explicit, documented pool-wide disposal operation, the built-in pool’s documented API examined here does not establish one. Evaluate a pool manager that documents this lifecycle operation, then verify its compatibility with the MySQL driver and how it handles connections still checked out when shutdown begins. No specific alternative was validated here, so a replacement should not be treated as a proven fix without checking its API and behavior against the deployed versions.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →How to investigate sockets that remain after shutdown
No single cause can be established without the application’s versions and shutdown details. Record the Connector/Python version, whether it uses the C extension or pure-Python implementation, the MySQL server version, how the pool is created, whether all borrowed connections are returned, and how the process terminates. Then reproduce the shutdown behavior in that deployment and inspect the socket owner and state. The available evidence does not establish exactly when a particular operating system or server releases sockets after process exit.
If the process is still running, check whether connections were returned to the pool and whether the pool is expected to keep them available for reuse. If the process has exited, distinguish application-level pool behavior from operating-system and server cleanup; the documented meaning of pooled close() alone cannot explain the observed timing.
Check version-specific close and reset failures
Historical reports show why an exception during close should be investigated separately from ordinary pool return behavior. An Oracle MySQL bug report describes an error closing pooled connections with Connector/Python 8.0.22–8.0.26, the C extension, and a MySQL server below 5.7.13. A MySQL developer response said the issue was fixed in Connector/Python 8.0.29. These are historical version-specific findings, not evidence that current releases have the same problem. See the Oracle MySQL bug report.
A separate report describes pooled connections becoming unavailable after a reset exception when the server connection was lost; it notes the behavior in the Connector/Python 2.1.6 changelog. If your shutdown produces an exception, capture the exact connector and server versions, connector mode, error, and connection-loss circumstances before applying an old report to a current installation. See the Oracle MySQL bug report.
Bottom line for the built-in pool
Return each checked-out connection with its close() method, but interpret that action as releasing the connection back to the pool. The documented API examined here does not provide a public pool-wide disposal method. If your application needs explicit socket teardown at shutdown, verify that lifecycle capability in a documented pool manager or confirm the actual process-exit behavior in your own deployment.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




