Skip to content

ConnectionError: The session was terminated unexpectedly  #483

Open
@WingZer0o

Description

@WingZer0o

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions