Reconnect with infinite retry attempts/timeout does not respond to `close()`
- Lingua principale
- TypeScript
- Stelle
- 635
- Fork
- 35
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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)
);
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.