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

Passing an empty array to batch throw an unexpected error

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 2.1.5
    • API
    • None

    Description

      see https://github.com/mariadb-corporation/mariadb-connector-nodejs/issues/94:
      connection.batch('INSERT INTO ...', [ ])
      will return a promise that rejects with the following

      TypeError: Cannot read property 'length' of undefined
          at BulkPacket.writeHeader (.../node_modules/mariadb/lib/io/bulk-packet.js:100:29)
          at new BulkPacket (.../node_modules/mariadb/lib/io/bulk-packet.js:41:10)
          at BatchBulk.start (.../node_modules/mariadb/lib/cmd/batch-bulk.js:73:19)
          at _addCommandEnablePipeline (.../node_modules/mariadb/lib/connection.js:1046:11)
          at .../node_modules/mariadb/lib/connection.js:201:7
          at new Promise (<anonymous>)
          at Connection.batch (.../node_modules/mariadb/lib/connection.js:194:12)
          at test (.../app.js:40:20)
          at <anonymous>
          at process._tickCallback (internal/process/next_tick.js:189:7)
      

      This arguably shouldn't reject since the idea of a batch is to apply the query to all elements in the array (which are themselves arrays) and an empty array should result in no queries being executed.

      But the larger issue comes from calling pool.batch('INSERT INTO ...', [ ])

      The promise rejects with the same error as above. But an uncaught error is also thrown:

       
      TypeError: Cannot read property 'waitingResponseNo' of undefined
          at BatchBulk.success (.../node_modules/mariadb/lib/cmd/batch-bulk.js:142:10)
          at BatchBulk.readPrepareResultPacket (.../node_modules/mariadb/lib/cmd/resultset.js:165:21)
          at PacketInputStream.receivePacketBasic (.../node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
          at PacketInputStream.onData (.../node_modules/mariadb/lib/io/packet-input-stream.js:160:20)
          at emitOne (events.js:116:13)
          at Socket.emit (events.js:211:7)
          at addChunk (_stream_readable.js:263:12)
          at readableAddChunk (_stream_readable.js:250:11)
          at Socket.Readable.push (_stream_readable.js:208:10)
          at TCP.onread (net.js:601:20)
      

      This uncaught error crashes the node process (unless process.on('uncaughtException', ...) is used).

      The expected behavior is for the library to never throw an uncaught error.

      I would guess the bug relates to Usually an array of array, but in cases of only one placeholder per value, it can be given as a single array. i.e. the second argument is handled differently for pool.batch than for connection.batch

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            diego dupin Diego Dupin
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.