denodrivers / denodrivers/postgres
ConnectionError: The session was terminated unexpectedly
- Dominant language
- TypeScript
- Stars
- 655
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I am using NeonPostgres and connecting to the database in Deno using the following below and executing this way. This connection is running in a Discord bot using Discordeno. I am entirely ruling out local network setup however the discord bot itself never disconnects. So that brings me here. After a certain time frame that I haven't determined quite yet. Maybe 20 minutes or so?
```typescript
import { Pool } from "https://deno.land/x/postgres@v0.19.3/mod.ts";
const pool = new Pool({
database: Deno.env.get("POSTGRES_DATABASE"),
hostname: Deno.env.get("POSTGRES_HOST"),
port: 5432,
user: Deno.env.get("POSTGRES_USER"),
password: Deno.env.get("POSTGRES_PASSWORD"),
connection: {
attempts: 10,
},
options: {
}
}, 10);
export { pool };
import { QueryArrayResult } from "https://deno.land/x/postgres@v0.19.3/mod.ts";
import { pool } from "../database/database.ts";
export class ChatMessageRepository {
public static async getChatMessagesByChannelIdAndUserId(channelId: bigint, userId: bigint): Promise> {
const client = await pool.connect();
const chatMesages = await client.queryArray(
`SELECT "Content", "IsBot" FROM public."ChatMessages" WHERE "ChannelId" = ${channelId} AND "UserId" = ${userId} ORDER BY "CreatedAt" ASC;`,
);
client.release();
return chatMesages;
}
}
```
```shell
ConnectionError: The session was terminated unexpectedly
0|chatbot | throw new ConnectionError("The session was terminated unexpectedly");
0|chatbot | ^
0|chatbot | at Connection.#readMessage (https://deno.land/x/postgres@v0.19.3/connection/connection.ts:186:13)
0|chatbot | at eventLoopTick (ext:core/01_core.js:168:7)
0|chatbot | at async Connection.#preparedQuery (https://deno.land/x/postgres@v0.19.3/connection/connection.ts:953:25)
0|chatbot | at async Connection.query (https://deno.land/x/postgres@v0.19.3/connection/connection.ts:979:18)
0|chatbot | at async PoolClient.#executeQuery (https://deno.land/x/postgres@v0.19.3/client.ts:256:12)
0|chatbot | at async PoolClient.queryArray (https://deno.land/x/postgres@v0.19.3/client.ts:339:12)
```
**Expected behavior**
I would expect the pool to maintain its "main" connection to the server so clients can connect on demand.
- deno-postgres version: 0.19.3
- deno version: 1.43.1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.