MySQL_Connector_Arduino
MySQL_Connector_Arduino copied to clipboard
MySQl deoesn't seem to close the connection properly
Dear Mr Bell,
I am running several ESP32 clients against a MariaDB server running on my Synology NAS.
The MariaDB log file is filling up with messages like:
2024-04-21` 14:32:36 170 [Warning] Aborted connection 170 to db: 'unconnected' user: 'coen' host: '192.168.178.4' (Got an error reading communication packets)
2024-04-21 14:33:18 172 [Warning] Aborted connection 172 to db: 'unconnected' user: 'coen' host: '192.168.178.181' (Got an error reading communication packets)
The code running on all these ESP32 is basically the same and comes down to:
WiFiClient` mySQLwifiClient;
MySQL_Connection conn((Client *)&mySQLwifiClient);
MySQL_Cursor cur = MySQL_Cursor(&conn);
bool connectToMySQL()
{
if (!conn.connected())
{
if (!conn.connect(server_addr, 3306, mySQLuser, mySQLpassword))
{
logTimedConstMessage("MySQL connect failed..\n");
return false;
}
logTimedConstMessage("MySQL connect succeeded..\n");
}
return true;
}
void execQuery(const char *query)
{
if (!connectToMySQL())
{
return;
}
// Execute the query
if (!cur.execute(query, false))
{
logTimedMessage("*** Exec query: '%s' failed..\n", query);
}
// Note: since there are no results, we do not need to read any data
cur.close();
conn.close();
}
After some 'research' on Google the only (possibly) relevant answer I could find is that the client doesn't seems to close the connection properly before exiting (does not call mysql_close()).
Looking at your code I don't see any code that implements some form of formal disconnect from the DB. The conn.close() call just closes the connection.
Am I missing something? Or does MariaDB behave differently than MySQL?
Any help on this issue would be greatly appropriated!
With kind regards,
Coen