Skip to content

Commit ecff60d

Browse files
authored
fix: Avoid retaining buffer for latest parse in reader (#3533)
* test: Add failing test for parser reader cleanup * fix: Avoid retaining buffer for latest parse in reader The buffer can be arbitrarily large, and the parser shouldn’t keep it around while waiting on (and potentially also buffering) the next complete packet.
1 parent 8d493f3 commit ecff60d

File tree

2 files changed

+215
-184
lines changed

2 files changed

+215
-184
lines changed

packages/pg-protocol/src/inbound-parser.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { parse } from '.'
44
import assert from 'assert'
55
import { PassThrough } from 'stream'
66
import { BackendMessage } from './messages'
7+
import { Parser } from './parser'
78

89
const authOkBuffer = buffers.authenticationOk()
910
const paramStatusBuffer = buffers.parameterStatus('client_encoding', 'UTF8')
@@ -565,4 +566,10 @@ describe('PgPacketStream', function () {
565566
})
566567
})
567568
})
569+
570+
it('cleans up the reader after handling a packet', function () {
571+
const parser = new Parser()
572+
parser.parse(oneFieldBuf, () => {})
573+
assert.strictEqual((parser as any).reader.buffer.byteLength, 0)
574+
})
568575
})

0 commit comments

Comments
 (0)