-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Reconnecting hangs when connection is terminated #14
Comments
Hey @Ingramz, thanks for reporting! Sorry for the delayed response. I saw the issue, but didn't have much time and couldn't see what might cause that behavior. Can you by any chance provide some sample code to reproduce the issue (maybe something unit-test-ish)? What caught my attention is the repeating |
This is pretty much the example code from readme, nothing special about it. const connectionString = 'YOUR CONNECTION STRING'
const createSubscriber = require('pg-listen')
// Accepts the same connection config object that the "pg" package would take
const subscriber = createSubscriber({ connectionString })
subscriber.notifications.on("my-channel", (payload) => {
// Payload as passed to subscriber.notify() (see below)
console.log("Received notification in 'my-channel':", payload)
})
subscriber.events.on("error", (error) => {
console.error("Fatal database connection error:", error)
process.exit(1)
})
process.on("exit", () => {
subscriber.close()
})
async function connect () {
await subscriber.connect()
await subscriber.listenTo("my-channel")
}
connect() Started it up using First I sent a payload to test if it works: Then I terminated the connection using the query I posted earlier. Finally I waited a little and then tried to send that same payload again. |
Memo to myself: |
Sorry that it took some time, but the issue is fixed now! A regression test has also been added. Thanks for the detailed report 🙌 |
No worries. So far it is working great, thanks! |
While attempting to produce a connection error, I noticed that pg-listen seems to never recover from termination:
Log:
The text was updated successfully, but these errors were encountered: