Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect with infinite retry attempts/timeout does not respond to close() #61

Open
laurence-myers opened this issue Jun 1, 2022 · 0 comments

Comments

@laurence-myers
Copy link

I'm implementing a worker process with the following requirements:

  • The notification listener should retry reconnecting indefinitely. (Infinite retry attempts, no timeout)
  • The worker process should respond to SIGINT signals, and gracefully terminate.

The "reconnect" loop does not respond to any signal from calling close(), so it will attempt to reconnect indefinitely. The promise hangs around and prevents the process from closing normally. (I've even seen odd behaviour where I've killed the process using kill -15 1234, and it returns to the terminal prompt, but I still see "reconnecting" messages logged. 😳)

A rough sketch:

import createPostgresSubscriber from "pg-listen";

async function demo() {
  try {
    process.on("SIGTERM", () => {
      console.log("Attempting graceful termination");
      await subscriber.close();
      console.log("Subscriber closed");
    });

    var subscriber = createPostgresSubscriber(
      {
        connectionString:
          "postgresql://invalid_user:invalid_password@localhost/postgres"
      },
      {
        retryInterval: 500,
        retryTimeout: Number.POSITIVE_INFINITY
      }
    );

    this.subscriber.events.on("reconnect", () => {
      console.log(`Reconnecting...`);
    });

    await subscriber.connect();
    await subscriber.listenTo("some_channel");
  } catch (err) {
    console.error(err);
  }
}

demo().then(
  () => console.log("Done"),
  err => console.error("Error", err)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant