mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
366 stars 91 forks source link

say "TypeError: Cannot read properties of undefined (reading 'charset')" after of 17 tryes #205

Closed aaferna closed 2 years ago

aaferna commented 2 years ago

Hi! im try to run this code:

const mariadb = require('mariadb');

exports.sql = (query) => {

        const pool = mariadb.createPool({
                host: config.mysql.server, 
                user: config.mysql.user, 
                password: config.mysql.password, 
                connectionLimit:  config.mysql.connectionreinten
            });

        async function sqlCore(query) {
            let conn;
            try {
                conn = await pool.getConnection();
                const rows = await conn.query(query);
                return rows
            } finally {
                if (conn) conn.release(); 
            }
        }

        return sqlCore(query)

}

////// in another js call the function 

sqlCore("SELECT clave, id_usuario FROM metronica_manager.usuarios WHERE nombredeusuario = 'aaferna'").then(
                    data => { ... } )

after of 17 tryes one after other, this crashes saying this:

D:\GitHub\metronicaAPI\metronicaAPI\node_modules\mariadb\lib\io\packet-output-stream.js:48
    this.encoding = collation.charset;
                              ^

TypeError: Cannot read properties of undefined (reading 'charset')
    at PacketOutputStream.changeEncoding (D:\GitHub\metronicaAPI\metronicaAPI\node_modules\mariadb\lib\io\packet-output-stream.js:48:31)
    at EventEmitter.emit (node:events:532:35)
    at Connection.<anonymous> (D:\GitHub\metronicaAPI\metronicaAPI\node_modules\mariadb\lib\connection.js:595:21)
    at Object.onceWrapper (node:events:640:26)
    at Handshake.emit (node:events:520:28)
    at Handshake.throwError (D:\GitHub\metronicaAPI\metronicaAPI\node_modules\mariadb\lib\cmd\command.js:90:10)
    at Handshake.parseHandshakeInit (D:\GitHub\metronicaAPI\metronicaAPI\node_modules\mariadb\lib\cmd\handshake\handshake.js:54:19)
    at PacketInputStream.receivePacketBasic (D:\GitHub\metronicaAPI\metronicaAPI\node_modules\mariadb\lib\io\packet-input-stream.js:76:9)
    at PacketInputStream.onData (D:\GitHub\metronicaAPI\metronicaAPI\node_modules\mariadb\lib\io\packet-input-stream.js:139:20)
    at Socket.emit (node:events:520:28)
[nodemon] app crashed - waiting for file changes before starting...
rusher commented 2 years ago

this correspond to error https://jira.mariadb.org/browse/CONJS-193 that occurs when having an error on connection. The Error is not displayed having this "Cannot read properties of undefined (reading 'charset')" in place. this will be corrected in 3.0.1 that is in the process of beeing released.

rusher commented 2 years ago

3.0.1 released