Search code examples
node.jspostgresqlgoogle-cloud-platformgoogle-cloud-sqlcloud-sql-proxy

Error "address already in use" when trying to connect to google cloud SQL using cloud-sql-connector


THE PROBLEM

When trying to connect to my cloud SQL database, I'm getting the following error.

Error: listen EADDRINUSE: address already in use /Users/josechavez/projectName/projectName/.s.PGSQL.5432
at Server.setupListenHandle [as _listen2] (node:net:1812:21)
at listenInCluster (node:net:1877:12)
at Server.listen (node:net:1976:5)
at node:internal/util:410:7
at new Promise (<anonymous>)
at Server.<anonymous> (node:internal/util:396:12)
at Connector.startLocalProxy (webpack-internal:///(rsc)/./node_modules/@google-cloud/cloud-sql-connector/dist/mjs/connector.js:207:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async connect (webpack-internal:///(rsc)/./src/app/lib/connect.ts:16:5)
at async prismaClientSingleton (webpack-internal:///(rsc)/./src/app/lib/prisma.ts:17:16) {
code: 'EADDRINUSE',

   errno: -48,
   syscall: 'listen',
   address: '/Users/josechavez/projectName/projectName/.s.PGSQL.5432',
   port: -1
}

I'm confident that all the previous steps, like authentication and configuration, are correct. But this error has no documentation or possible solutions.

I've tried with 5432, 5433, ... and so on. but nothing still.

This is how I'm connecting my NextJS app to my cloudSQL database

I've also tried to use this whole path that is mentioned in the docs /cloudsql/INSTANCE_CONNECTION_NAME/.s.PGSQL.5432

But this time I get an error that says no access/view permissions, but I'm not sure if this is the way.

Someone please help me, Thanks in advance!


Solution

  • As described in the following issue. The error was indeed because of the file that was being generated. That file must be deleted before trying again.

    Anyways, This is the core problem I was facing, in case someone is interested, which is related to this question