Skip to content
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

ConnectionError: The session was terminated unexpectedly #483

Open
WingZer0o opened this issue May 11, 2024 · 0 comments
Open

ConnectionError: The session was terminated unexpectedly #483

WingZer0o opened this issue May 11, 2024 · 0 comments

Comments

@WingZer0o
Copy link

WingZer0o commented May 11, 2024

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?

import { Pool } from "https://deno.land/x/[email protected]/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/[email protected]/mod.ts";
import { pool } from "../database/database.ts";

export class ChatMessageRepository {

    public static async getChatMessagesByChannelIdAndUserId(channelId: bigint, userId: bigint): Promise<QueryArrayResult<unknown[]>> {
        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;
    }
}
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/[email protected]/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/[email protected]/connection/connection.ts:953:25)
0|chatbot  |     at async Connection.query (https://deno.land/x/[email protected]/connection/connection.ts:979:18)
0|chatbot  |     at async PoolClient.#executeQuery (https://deno.land/x/[email protected]/client.ts:256:12)
0|chatbot  |     at async PoolClient.queryArray (https://deno.land/x/[email protected]/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant