Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/partial-result-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class PartialResultStream extends Transform implements ResultEvents {
}

if (chunk.last) {
this.emit('end');
this.push(null);
return;
}

Expand Down
42 changes: 42 additions & 0 deletions test/partial-result-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,48 @@ describe('PartialResultStream', () => {
});
});
});

it('should not lose data if paused when last chunk is received', done => {
const stream = new PartialResultStream({});
// Pause the stream initially to force buffering
stream.pause();

const rows: any[] = [];
stream.on('data', row => rows.push(row));
stream.on('end', () => {
try {
// We expect 2 rows.
assert.strictEqual(rows.length, 2);
done();
} catch (e) {
done(e);
}
});

const fields = [{name: NAME, type: {code: 'STRING'}}];

// Write a normal chunk
stream.write({
metadata: {rowType: {fields}},
values: [convertToIValue('row1')],
resumeToken: 't1',
});

// Write the last chunk immediately
stream.write({
values: [convertToIValue('row2')],
resumeToken: 't2',
last: true,
});

// Resume after a tick.
// If emit('end') was called synchronously during write, the 'end' event might fire
// and close the stream before we consume the buffered 'row1' and 'row2'.
// With push(null), it waits for buffer to drain.
process.nextTick(() => {
stream.resume();
});
});
});

describe('partialResultStream', () => {
Expand Down
Loading