Uploaded image for project: 'MariaDB Connector/node.js'
  1. MariaDB Connector/node.js
  2. CONJS-193

Wrong error returned "Cannot read properties of undefined… … (reading 'charset')" when error during handshake

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.0.1
    • other
    • None
    • MariaDB 10.2.7

    Description

      The following code throws an exception with MariaDB 10.2 whereas with 10.6 it just works.

      [
        { val: 1n },
        meta: [
          ColumnDef {
            _stringParser: [StringParser],
            collation: [Collation],
            columnLength: 1,
            columnType: 8,
            flags: 129,
            scale: 0,
            type: 'BIGINT'
          }
        ]
      ]
      undefined
      /home/markusjm/sqltest/nodejs/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 (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/io/packet-output-stream.js:48:31)
          at EventEmitter.emit (node:events:532:35)
          at Connection.<anonymous> (/home/markusjm/sqltest/nodejs/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 (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/cmd/command.js:90:10)
          at Handshake.parseHandshakeInit (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/cmd/handshake/handshake.js:54:19)
          at PacketInputStream.receivePacketBasic (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/io/packet-input-stream.js:76:9)
          at PacketInputStream.onData (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/io/packet-input-stream.js:139:20)
          at Socket.emit (node:events:520:28)
      

      const mariadb = require("mariadb")
      const pool = mariadb.createPool({
          host: '127.0.0.1',
          port: 3000,
          user:'maxuser',
          password: 'maxpwd',
          connectionLimit: 100
      });
      async function asyncFunction() {
          let conn;
          try {
              conn = await pool.getConnection();
              const rows = await conn.query("SELECT 1 as val");
              console.log(rows); //[ {val: 1}, meta: ... ]                                                                                                                                                                                                                                      
              const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
              console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }                                                                                                                                                                                                           
          } catch (err) {
              throw err;
          } finally {
              if (conn) return conn.end();
          }
      }
      asyncFunction().then(console.log, console.log)
      

      Attachments

        Activity

          diego dupin Diego Dupin added a comment -

          It doesn't seems to be related with server version 10.2 at all.
          Connector is throwing an exception because of wrong handshake, but return a wrong error "Cannot read properties of undefined (reading 'charset')" in place of initial error, if receiving no handshake / or an handshake packet with a 0x00 charset byte.

          This part will be corrected with https://github.com/mariadb-corporation/mariadb-connector-nodejs/commit/5121d6cf1b32d25167ef9f385a0c78cf6554a4d3
          Could you confirm markus makela that server was not up or something like that ?

          diego dupin Diego Dupin added a comment - It doesn't seems to be related with server version 10.2 at all. Connector is throwing an exception because of wrong handshake, but return a wrong error "Cannot read properties of undefined (reading 'charset')" in place of initial error, if receiving no handshake / or an handshake packet with a 0x00 charset byte. This part will be corrected with https://github.com/mariadb-corporation/mariadb-connector-nodejs/commit/5121d6cf1b32d25167ef9f385a0c78cf6554a4d3 Could you confirm markus makela that server was not up or something like that ?
          markus makela markus makela added a comment -

          Testing it again with the 10.2.7 image does show that it now works when connecting directly as well as through MaxScale. The server was most definitely up when I tested it as it returned a resultset before throwing that exception.

          markus makela markus makela added a comment - Testing it again with the 10.2.7 image does show that it now works when connecting directly as well as through MaxScale. The server was most definitely up when I tested it as it returned a resultset before throwing that exception.
          diego dupin Diego Dupin added a comment -

          thanks markus, i will then close the task changing to label to wrong error returned "Cannot read properties of undefined… … (reading 'charset')" when error during handshake

          diego dupin Diego Dupin added a comment - thanks markus, i will then close the task changing to label to wrong error returned "Cannot read properties of undefined… … (reading 'charset')" when error during handshake

          People

            diego dupin Diego Dupin
            markus makela markus makela
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.