Skip to content

Commit 728e337

Browse files
committed
fix: handle minor memory leak
1 parent 84bf1d2 commit 728e337

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/pg-driver/src/factories/createPgDriverFactory.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,22 @@ export const createPgDriverFactory = (): DriverFactory => {
340340
// `rowDescription` will not fire if the query produces a syntax error.
341341
// Also, `rowDescription` won't fire until client starts consuming the stream.
342342
// This is why we cannot simply await for `rowDescription` event before starting to pipe the stream.
343-
client.connection.once('rowDescription', (rowDescription) => {
343+
const onRowDescription = (rowDescription) => {
344344
fields = rowDescription.fields.map((field) => {
345345
return {
346346
dataTypeId: field.dataTypeID,
347347
name: field.name,
348348
};
349349
});
350+
};
351+
352+
client.connection.once('rowDescription', onRowDescription);
353+
354+
stream.once('close', () => {
355+
client.connection.removeListener(
356+
'rowDescription',
357+
onRowDescription,
358+
);
350359
});
351360

352361
const transform = new Transform({

0 commit comments

Comments
 (0)