supavisor icon indicating copy to clipboard operation
supavisor copied to clipboard

ClientHandler: socket closed with reason {:shutdown, :db_handler_exit} on supabase.com pooler logs

Open mpdaugherty opened this issue 1 year ago • 0 comments

Bug report

  • [X] I confirm this is a bug with Supabase, not with my own application.
  • [X] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I'm getting failures when connecting to postgres hosted on supabase.com non-deterministically. I'm calling via pg in an AWS lambda written in Javascript. The error message is ""DbHandler exited" and happens right when I call pool.connect().

When digging in on supabase.com, I found that I can see this error in the pooler logs, with nothing unusual happening in the postgres logs.

Screenshot:

Cursor_and_Pooler_Logs___Supabase

This seems to happen in 10-20% of calls, but I don't have enough volume in this lambda to narrow it down more than that.

This is on a Micro supabase instance.

To Reproduce

Javascript code:

// db.js
const { Pool } = require('pg')
const { Buffer } = require('buffer') // For base64 decoding

const PG_PARAMS = {
  connectionString: process.env.POSTGRES,
}

// Check if we are not in local development
if (process.env.NODE_ENV !== 'dev') {
  // Assuming your SSL cert is base64 encoded in an environment variable
  // Decode the base64 encoded certificate
  const decodedCert = Buffer.from(process.env.DATABASE_SSL_CERT, 'base64').toString('utf-8')

  PG_PARAMS.ssl = {
    rejectUnauthorized: true, // Set to true for production use
    ca: decodedCert, // Use the decoded certificate
  }
}

// We should be using the 6543 port for connection pooling with transaction-level isolation
const pool = new Pool(PG_PARAMS)

async function getDBClient() {
  return pool.connect()
}

module.exports = {
  db: pool,
  getDBClient,
}
// ...

  const db = await getDBClient()
  if (LOG_DEBUG) console.log('Database client obtained')
// ...

'Database client obtained' is never logged when this error happens.

Expected behavior

I expect the database connection to connect and not exit.

System information

  • OS: Amazon Lambda
  • Version of Node.js: Node.js 20.x

mpdaugherty avatar Oct 05 '24 02:10 mpdaugherty