node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

Packet.readLengthCodedNumberExt exception

Open perry-mitchell opened this issue 4 years ago • 5 comments

Getting a random exception thrown between mysql2 and a MySQL 8 (8.0.23-0ubuntu0.20.04.1) database (from Node 12):

service_1  | Trace
service_1  |     at Packet.readLengthCodedNumberExt (/data/node_modules/mysql2/lib/packets/packet.js:226:13)
service_1  |     at Packet.readLengthCodedNumber (/data/node_modules/mysql2/lib/packets/packet.js:188:17)
service_1  |     at new ColumnDefinition (/data/node_modules/mysql2/lib/packets/column_definition.js:28:33)
service_1  |     at Prepare.readParameter (/data/node_modules/mysql2/lib/commands/prepare.js:79:17)
service_1  |     at Prepare.execute (/data/node_modules/mysql2/lib/commands/command.js:39:22)
service_1  |     at Connection.handlePacket (/data/node_modules/mysql2/lib/connection.js:425:32)
service_1  |     at PacketParser.onPacket (/data/node_modules/mysql2/lib/connection.js:75:12)
service_1  |     at PacketParser.executeStart (/data/node_modules/mysql2/lib/packet_parser.js:75:16)
service_1  |     at Socket.<anonymous> (/data/node_modules/mysql2/lib/connection.js:82:25)
service_1  |     at Socket.emit (events.js:314:20)
service_1  | /data/node_modules/mysql2/lib/packets/packet.js:227
service_1  |     throw new Error(`Should not reach here: ${tag}`);
service_1  |     ^
service_1  |
service_1  | Error: Should not reach here: undefined
service_1  |     at Packet.readLengthCodedNumberExt (/data/node_modules/mysql2/lib/packets/packet.js:227:11)
service_1  |     at Packet.readLengthCodedNumber (/data/node_modules/mysql2/lib/packets/packet.js:188:17)
service_1  |     at new ColumnDefinition (/data/node_modules/mysql2/lib/packets/column_definition.js:28:33)
service_1  |     at Prepare.readParameter (/data/node_modules/mysql2/lib/commands/prepare.js:79:17)
service_1  |     at Prepare.execute (/data/node_modules/mysql2/lib/commands/command.js:39:22)
service_1  |     at Connection.handlePacket (/data/node_modules/mysql2/lib/connection.js:425:32)
service_1  |     at PacketParser.onPacket (/data/node_modules/mysql2/lib/connection.js:75:12)
service_1  |     at PacketParser.executeStart (/data/node_modules/mysql2/lib/packet_parser.js:75:16)
service_1  |     at Socket.<anonymous> (/data/node_modules/mysql2/lib/connection.js:82:25)
service_1  |     at Socket.emit (events.js:314:20)

The app, which has seen no recent modifications of queries or mysql2, is running out of a docker container. It's accessing a DB contained within a vagrant machine. This is a new development setup so not ruling environmental factors out, but it seems strange that it'd suddenly die like this during normal operation.

The query causing the issue:

SELECT a.id, a.question_id, a.text, a.next_no, a.score, a.score2, a.is_end, a.is_live_chat, a.url, a.category_id, a.gtm_event_name, a.label_id, a.priority, l.name AS label_name, l.value AS label_value
FROM answer a LEFT JOIN label l ON l.id = a.label_id WHERE a.question_id = ? ORDER BY ? ASC

Parameters: [ 3370, 'a.priority' ]

Running this query manually works fine, returning results.

EDIT: Using mysql2 2.2.5

perry-mitchell avatar Feb 22 '21 09:02 perry-mitchell

I can see it's the same error message as #1207, but I'm not using any proxy.

perry-mitchell avatar Feb 22 '21 11:02 perry-mitchell

Got the same error with: Macos Big Sur, Mysql 8.0.23 and node-mysql 2.2.5.

Doesn't happen with Mysql 5.7.31.

vasyas avatar Mar 01 '21 12:03 vasyas

@vasyas would you able to reduce to some small self contained example I can try to debug locally with Mysql 8.0.23 from docker?

sidorares avatar Mar 02 '21 01:03 sidorares

I'm still seeing this issue, with different queries.. This one fails for me:

SELECT
             a.category_id, a.gtm_event_name, a.id, a.img_answer, a.is_end, a.is_live_chat, a.label_id, a.meta, a.next_no, a.priority, a.question_id, a.score, a.score2, a.sub_text, a.text, a.url, l.name AS label_name, l.value AS label_value
         FROM `answer` a
         LEFT JOIN `label` l ON (l.id = a.label_id)
         WHERE a.question_id = ? ORDER BY ? ASC

With the params: [ 3591, "a.order" ]

However, if I remove the a.order parameter and hard-code it in the query, it works:

SELECT
             a.category_id, a.gtm_event_name, a.id, a.img_answer, a.is_end, a.is_live_chat, a.label_id, a.meta, a.next_no, a.priority, a.question_id, a.score, a.score2, a.sub_text, a.text, a.url, l.name AS label_name, l.value AS label_value
         FROM `answer` a
         LEFT JOIN `label` l ON (l.id = a.label_id)
         WHERE a.question_id = ? ORDER BY a.order ASC

With the params: [ 3591 ]

The output is the same
service_1  | Trace
service_1  |     at Packet.readLengthCodedNumberExt (/data/node_modules/mysql2/lib/packets/packet.js:226:13)
service_1  |     at Packet.readLengthCodedNumber (/data/node_modules/mysql2/lib/packets/packet.js:188:17)
service_1  |     at new ColumnDefinition (/data/node_modules/mysql2/lib/packets/column_definition.js:28:33)
service_1  |     at Prepare.readParameter (/data/node_modules/mysql2/lib/commands/prepare.js:79:17)
service_1  |     at Prepare.execute (/data/node_modules/mysql2/lib/commands/command.js:39:22)
service_1  |     at Connection.handlePacket (/data/node_modules/mysql2/lib/connection.js:425:32)
service_1  |     at PacketParser.onPacket (/data/node_modules/mysql2/lib/connection.js:75:12)
service_1  |     at PacketParser.executeStart (/data/node_modules/mysql2/lib/packet_parser.js:75:16)
service_1  |     at Socket.<anonymous> (/data/node_modules/mysql2/lib/connection.js:82:25)
service_1  |     at Socket.emit (events.js:315:20)
service_1  | /data/node_modules/mysql2/lib/packets/packet.js:227
service_1  |     throw new Error(`Should not reach here: ${tag}`);
service_1  |     ^
service_1  |
service_1  | Error: Should not reach here: undefined
service_1  |     at Packet.readLengthCodedNumberExt (/data/node_modules/mysql2/lib/packets/packet.js:227:11)
service_1  |     at Packet.readLengthCodedNumber (/data/node_modules/mysql2/lib/packets/packet.js:188:17)
service_1  |     at new ColumnDefinition (/data/node_modules/mysql2/lib/packets/column_definition.js:28:33)
service_1  |     at Prepare.readParameter (/data/node_modules/mysql2/lib/commands/prepare.js:79:17)
service_1  |     at Prepare.execute (/data/node_modules/mysql2/lib/commands/command.js:39:22)
service_1  |     at Connection.handlePacket (/data/node_modules/mysql2/lib/connection.js:425:32)
service_1  |     at PacketParser.onPacket (/data/node_modules/mysql2/lib/connection.js:75:12)
service_1  |     at PacketParser.executeStart (/data/node_modules/mysql2/lib/packet_parser.js:75:16)
service_1  |     at Socket.<anonymous> (/data/node_modules/mysql2/lib/connection.js:82:25)
service_1  |     at Socket.emit (events.js:315:20)

EDIT: Would this indicate that it's breaking in preparing the query when using column names as parameters?

perry-mitchell avatar Apr 06 '21 10:04 perry-mitchell

Check the version of mysql, 5.7 is useful

hcd660 avatar Aug 01 '22 07:08 hcd660