2

I have a Vercel deployed Remix project with Supabase on the backend, Postgresql and using Prisma as the ORM. I have set up connection pooling as well as a direct connection to Supabase, but anytime I try to connect either locally I get this error:

🔌 setting up prisma client to undefined.db.ubixifkwxkflnueueaku.supabase.co:6543
✅ app ready: http://localhost:3000
✅ metrics ready: http://localhost:3001/metrics

C:\Users\TylerD\Desktop\dev\TheCityGomorrah\node_modules\@prisma\client\runtime\library.js:101
You may have to run ${Gt.default.greenBright("prisma generate")} for your changes to take effect.`,this.config.clientVersion);return r}parseEngineResponse(r){if(!r)throw new W("Response from the Engine was empty",{clientVersion:this.config.clientVersion});try{return JSON.parse(r)}catch{throw new W("Unable to JSON.parse response from engine",{clientVersion:this.config.clientVersion})}}convertDatasources(r){let n=Object.create(null);for(let{name:i,url:o}of r)n[i]=o;return n}async loadEngine(){if(!this.engine){this.QueryEngineConstructor||(this.library=await this.libraryLoader.loadLibrary(),this.QueryEngineConstructor=this.library.QueryEngine);try{let r=new WeakRef(this);this.engine=new this.QueryEngineConstructor({datamodel:this.datamodel,env:process.env,logQueries:this.config.logQueries??!1,ignoreEnvVarErrors:!0,datasourceOverrides:this.datasourceOverrides,logLevel:this.logLevel,configDir:this.config.cwd,engineProtocol:this.engineProtocol},n=>{r.deref()?.logger(n)}),Nl++}catch(r){let n=r,i=this.parseInitError(n.message);throw typeof i=="string"?n:new G(i.message,this.config.clientVersion,i.error_code)}}}logger(r){let n=this.parseEngineResponse(r);if(!!n){if("span"in n){this.config.tracingConfig.enabled===!0&&co(n);return}n.level=n?.level.toLowerCase()??"unknown",Vd(n)?this.logEmitter.emit("query",{timestamp:new Date,query:n.query,params:n.params,duration:Number(n.duration_ms),target:n.module_path}):Qd(n)?this.loggerRustPanic=new ce(this.getErrorMessageWithLink(`${n.message}: ${n.reason} in ${n.file}:${n.line}:${n.column}`),this.config.clientVersion):this.logEmitter.emit(n.level,{timestamp:new Date,message:n.message,target:n.module_path})}}getErrorMessageWithLink(r){return Ya({platform:this.platform,title:r,version:this.config.clientVersion,engineVersion:this.versionInfo?.commit,database:this.config.activeProvider,query:this.lastQuery})}parseInitError(r){try{return JSON.parse(r)}catch{}return r}parseRequestError(r){try{return JSON.parse(r)}catch{}return r}on(r,n){r==="beforeExit"?this.beforeExitListener=n:this.logEmitter.on(r,n)}async start(){if(await this.libraryInstantiationPromise,await this.libraryStoppingPromise,this.libraryStartingPromise)return je(`library already starting, this.libraryStarted: ${this.libraryStarted}`),this.libraryStartingPromise;if(this.libraryStarted)return;let r=l(async()=>{je("library starting");try{let i={traceparent:Ne({tracingConfig:this.config.tracingConfig})};await this.engine?.connect(JSON.stringify(i)),this.libraryStarted=!0,je("library started")}catch(i){let o=this.parseInitError(i.message);throw typeof o=="string"?i:new G(o.message,this.config.clientVersion,o.error_code)}finally{this.libraryStartingPromise=void 0}},"startFn"),n={name:"connect",enabled:this.config.tracingConfig.enabled};return this.libraryStartingPromise=fe(n,r),this.libraryStartingPromise}async stop(){if(await this.libraryStartingPromise,await this.executingQueryPromise,this.libraryStoppingPromise)return je("library is already stopping"),this.libraryStoppingPromise;if(!this.libraryStarted)return;let r=l(async()=>{await new Promise(o=>setTimeout(o,5)),je("library stopping");let i={traceparent:Ne({tracingConfig:this.config.tracingConfig})};await this.engine?.disconnect(JSON.stringify(i)),this.libraryStarted=!1,this.libraryStoppingPromise=void 0,je("library stopped")},"stopFn"),n={name:"disconnect",enabled:this.config.tracingConfig.enabled};return this.libraryStoppingPromise=fe(n,r),this.libraryStoppingPromise}async getDmmf(){await this.start();let r=Ne({tracingConfig:this.config.tracingConfig}),n=await this.engine.dmmf(JSON.stringify({traceparent:r}));return fe({name:"parseDmmf",enabled:this.config.tracingConfig.enabled,internal:!0},()=>JSON.parse(n))}version(){return this.versionInfo=this.library?.version(),this.versionInfo?.version??"unknown"}debugPanic(r){return this.library?.debugPanic(r)}async request(r,{traceparent:n,interactiveTransaction:i}){je(`sending request, this.libraryStarted: ${this.libraryStarted}`);let o=JSON.stringify({traceparent:n}),s=JSON.stringify(r);try{await this.start(),this.executingQueryPromise=this.engine?.query(s,o,i?.id),this.lastQuery=s;let a=this.parseEngineResponse(await this.executingQueryPromise);if(a.errors)throw a.errors.length===1?this.buildQueryError(a.errors[0]):new W(JSON.stringify(a.errors),{clientVersion:this.config.clientVersion});if(this.loggerRustPanic)throw this.loggerRustPanic;return{data:a,elapsed:0}}catch(a){if(a instanceof G)throw a;if(a.code==="GenericFailure"&&a.message?.startsWith("PANIC:"))throw new ce(this.getErrorMessageWithLink(a.message),this.config.clientVersion);let u=this.parseRequestError(a.message);throw typeof u=="string"?a:new W(`${u.message}
                                                                                                                                          
     ^
Error: Can't reach database server at `undefined.db.ubixifkwxkflnueueaku.supabase.co`:`6543`

Please make sure your database server is running at `undefined.db.ubixifkwxkflnueueaku.supabase.co`:`6543`.
    at startFn (C:\Users\TylerD\Desktop\dev\TheCityGomorrah\node_modules\@prisma\client\runtime\library.js:101:2598)

Likewise, if I attempt to register a User in the Vercel deployment, it works but does not store anything in the database. But upon attempted login, it gives me a similar error in the Vercel logs:

Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`\n\nPlease make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","reason":{"errorType":"Error","errorMessage":"Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`\n\nPlease make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","clientVersion":"4.11.0","errorCode":"P1001","stack":["Error: Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`","","Please make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","    at startFn (/var/task/node_modules/@prisma/client/runtime/library.js:101:2598)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`","","Please make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","    at process.<anonymous> (file:///var/runtime/index.mjs:1188:17)","    at process.emit (node:events:525:35)","    at process.emit (/var/task/node_modules/source-map-support/source-map-support.js:516:21)","    at emit (node:internal/process/promises:149:20)","    at processPromiseRejections (node:internal/process/promises:283:27)","    at processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
Unknown application error occurred
Runtime.Unknown

Now obviously with nothing storing in the DB, I can't retrieve it either. But for clarity sake, these are the logs.

My .env has the DATABASE_URL which is for connection pooling, and DIRECT_URL for migration updates etc - I've double checked credentials, and scoured both Prisma and Supabase's docs, and I've looked on the GH issues pages and couldn't find anything regarding this.

The Supabase logs return this:

Log ID
bba2af3c-2839-40ca-be4a-44a7c54dcb2c

Log Timestamp (UTC)
2023-04-02T21:44:16.257Z

Log Event Message
C-0xaaaadd3c6810: pgbouncer/[email protected]:56654 closing because: SASL authentication failed (age=0s)

Log Metadata
[
  {
    "PRIORITY": null,
    "SYSLOG_FACILITY": null,
    "SYSLOG_IDENTIFIER": null,
    "_BOOT_ID": null,
    "_CAP_EFFECTIVE": null,
    "_CMDLINE": null,
    "_COMM": null,
    "_EXE": null,
    "_GID": null,
    "_MACHINE_ID": null,
    "_PID": null,
    "_SELINUX_CONTEXT": null,
    "_SOURCE_REALTIME_TIMESTAMP": null,
    "_STREAM_ID": null,
    "_SYSTEMD_CGROUP": null,
    "_SYSTEMD_INVOCATION_ID": null,
    "_SYSTEMD_SLICE": null,
    "_SYSTEMD_UNIT": null,
    "_TRANSPORT": null,
    "_UID": null,
    "__MONOTONIC_TIMESTAMP": null,
    "__REALTIME_TIMESTAMP": null,
    "file": null,
    "host": "db-ubixifkwxkflnueueaku",
    "metadata": [],
    "project": null,
    "source_type": null
  }
]

2 Answers 2

1

It seems that you are deploying the app from one of the Remix template stacks — be aware that app/db.server.ts by default includes a bunch of FLY.io specific configs. (hint: you can grep the error message 🔌 setting up prisma client to to find the file)

Specifically, this part:

    if (!isLocalHost) {
      databaseUrl.host = `${FLY_REGION}.${databaseUrl.host}`

reads FLY_REGION environment variable, and if that env var is missing, it will be evaluated as "undefined.{database_url}", which is precisely what you're seeing here.

Sign up to request clarification or add additional context in comments.

Comments

1

I had this exact same thing happen to me today. The problem is that when you set it up to be deployed on fly. It will automatically add a bunch of extra configuration in the app/db.server.ts file. Specifically, manipulating the prisma client in the getClient() function.

My suggestion (to get up and running quickly is to just replace with this):

function getClient() {
  const { DATABASE_URL } = process.env;
  invariant(typeof DATABASE_URL === "string", "DATABASE_URL env var not set");
  console.log(`🔌 setting up prisma client to DATABASE_URL`);

  const client = new PrismaClient()

  // connect eagerly
  client.$connect();

  return client;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.