Reconnect with infinite retry attempts/timeout does not respond to `close()`
- Dominant language
- TypeScript
- Stars
- 635
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
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:
```typescript
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)
);
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.