The connection reserved for LISTEN is not closed after the last subscribed-to channel is unsubscribed from
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
I noticed that the Node.js process does not come to an end after using the listening mechanism. That's because the connection reserved for LISTEN statements is not closed even after the last channel is unsubscribed from. And even if all other connections are closed via close().
Use this program:
const sql = require("postgres")(...);
sql.listen("topic", console.log.bind(null, "Received:"), async () => {
await sql.unsafe(`SELECT pg_notify('topic', 'something')`);
}).then(({ unlisten }) => {
setTimeout(async () => {
await sql.close();
await unlisten();
// sql.unsafe(`SELECT 1`);
}, 1000);
});
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the JavaScript reproduction in the issue and inspect the listen/unlisten connection lifecycle. The fix is complete when closing the client and unsubscribing from the last channel allow the Node.js process to exit without another query keeping the connection open.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, postgresql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100