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

"pg-query-stream" stream does not emit an error when there are multiple open connections

Open GregoryPevnev opened this issue 3 years ago • 1 comments

import { Client, Pool } from 'pg';
import QueryStream from 'pg-query-stream';

const settings1 = {
  host: 'postgres-1',
  port: 5432,
  user: 'postgres',
  password: 'postgres',
  database: 'postgres',
};

const settings2 = {
  host: 'postgres-2',
  port: 5432,
  user: 'postgres',
  password: 'postgres',
  database: 'postgres',
};

const testConnections = async () => {
  const client1 = new Client(settings1);

  await client1.connect();

  const stream = client1.query(new QueryStream('SELECT * FROM none;'));

  const client2 = new Client(settings2);

  // Comment out to make everything work (The problem is a pending connection)
  await client2.connect();

  try {
    console.log('READING');

    // Stops here
    for await (const record of stream) {
      console.log(record);
    }

    console.log('SUCCESS');
  } catch (error) {
    console.log('ERROR');

    throw error;
  } finally {
    await client1.end();
    await client2.end();
  }
};

testConnections();

This gives the following output (the program never finishes, it just remains pending).

> ts-node -r tsconfig-paths/register  "./src/pg-streams-testing.ts"

READING

GregoryPevnev avatar Feb 17 '22 15:02 GregoryPevnev

@GregoryPevnev Did you ever find a workaround or resolution?

idahogurl avatar Jul 28 '22 20:07 idahogurl