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

RangeError [ERR_OUT_OF_RANGE] when parsing result fields

Open ubnt-michals opened this issue 5 years ago • 3 comments

I am getting following error:

https://sentry.io/share/issue/dc40781d83fd437184bca7ee5cde56be/

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 1074. Received 2377
  File "internal/buffer.js", line 49, col 9, in boundsError
  File "internal/buffer.js", line 361, col 5, in Buffer.readInt32BE
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 630, col 22, in Connection.parseInt32
    var value = buffer.readInt32BE(this.offset)
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 535, col 21, in Connection._readValue
    var length = this.parseInt32(buffer)
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 528, col 26, in Connection.parseD
    msg.fields.push(this._readValue(buffer))
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 377, col 19, in Connection.parseMessage
    return this.parseD(buffer, length)
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 120, col 22, in Socket.<anonymous>
    var msg = self.parseMessage(packet)
  File "events.js", line 189, col 13, in Socket.emit
  File "domain.js", line 441, col 20, in Socket.EventEmitter.emit
  File "_stream_readable.js", line 284, col 12, in addChunk
  File "_stream_readable.js", line 265, col 11, in readableAddChunk
  File "_stream_readable.js", line 220, col 10, in Socket.Readable.push
  File "internal/stream_base_commons.js", line 94, col 17, in TCP.onStreamRead [as onread]
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 542. Received -19
  File "internal/buffer.js", line 49, col 9, in boundsError
  File "internal/buffer.js", line 361, col 5, in Buffer.readInt32BE
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 630, col 22, in Connection.parseInt32
    var value = buffer.readInt32BE(this.offset)
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 535, col 21, in Connection._readValue
    var length = this.parseInt32(buffer)
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 528, col 26, in Connection.parseD
    msg.fields.push(this._readValue(buffer))
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 377, col 19, in Connection.parseMessage
    return this.parseD(buffer, length)
  File "/home/app/unms/node_modules/pg/lib/connection.js", line 120, col 22, in Socket.<anonymous>
    var msg = self.parseMessage(packet)
  File "events.js", line 189, col 13, in Socket.emit
  File "domain.js", line 441, col 20, in Socket.EventEmitter.emit
  File "_stream_readable.js", line 284, col 12, in addChunk
  File "_stream_readable.js", line 265, col 11, in readableAddChunk
  File "_stream_readable.js", line 220, col 10, in Socket.Readable.push
  File "internal/stream_base_commons.js", line 94, col 17, in TCP.onStreamRead [as onread]
  • pg - 7.8.0
  • postgesql - 9.6.12

I don't have failing server response yet, I am still trying to reproduce the issue.

ubnt-michals avatar Jan 02 '20 11:01 ubnt-michals

that looks weird/bad - lemme know if you can get steps to reproduce!

brianc avatar Jan 10 '20 05:01 brianc

I'm getting this issue as well unfortunately with my data set trying to query multiple rows. If anyone has any idea what causes it that would be amazing. The error is slightly different though:

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 14. Received 16

seantcanavan avatar Dec 15 '21 21:12 seantcanavan

We saw several crashes caused by this today:

ERROR 2025-04-11T20:01:38.854413215Z RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 5888. Received 5892
ERROR 2025-04-11T20:01:38.854418835Z at boundsError (node:internal/buffer:88:9)
ERROR 2025-04-11T20:01:38.854425665Z at Buffer.readInt32BE (node:internal/buffer:484:5)
ERROR 2025-04-11T20:01:38.854432025Z at BufferReader.int32 (/home/node/app/Backend/node_modules/pg-protocol/dist/buffer-reader.js:27:36)
ERROR 2025-04-11T20:01:38.854440505Z at Parser.parseField (/home/node/app/Backend/node_modules/pg-protocol/dist/parser.js:189:40)
ERROR 2025-04-11T20:01:38.854445825Z at Parser.parseRowDescriptionMessage (/home/node/app/Backend/node_modules/pg-protocol/dist/parser.js:181:38)
ERROR 2025-04-11T20:01:38.854451285Z at Parser.handlePacket (/home/node/app/Backend/node_modules/pg-protocol/dist/parser.js:126:29)
ERROR 2025-04-11T20:01:38.854456625Z at Parser.parse (/home/node/app/Backend/node_modules/pg-protocol/dist/parser.js:35:38)
ERROR 2025-04-11T20:01:38.854487275Z at Socket.<anonymous> (/home/node/app/Backend/node_modules/pg-protocol/dist/index.js:11:42)
ERROR 2025-04-11T20:01:38.854491105Z at Socket.emit (node:events:524:28)
ERROR 2025-04-11T20:01:38.854494515Z at addChunk (node:internal/streams/readable:561:12) {
ERROR 2025-04-11T20:01:38.854499035Z code: 'ERR_OUT_OF_RANGE'
ERROR 2025-04-11T20:01:38.854502065Z }

As far as I can tell the query itself wasn't logged anywhere.

christhegrand avatar Apr 11 '25 22:04 christhegrand