serverless icon indicating copy to clipboard operation
serverless copied to clipboard

TypeError: fetch failed] { cause: [Error: AggregateError] }

Open tapz opened this issue 1 year ago • 5 comments

Steps to reproduce

const sql = neon(process.env.POSTGRES_URL_NON_POOLING);
return await sql(query, params);

Expected result

Return rows

Actual result

Error

Environment

Vercel Edge Runtime

Logs, links

Work with Kysely and Pool, but this does not work:

const sql = neon(process.env.POSTGRES_URL_NON_POOLING);
return await sql(query, params);
[NeonDbError: Error connecting to database: fetch failed] {
  name: 'NeonDbError',
  severity: undefined,
  code: undefined,
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: undefined,
  line: undefined,
  routine: undefined,
  sourceError: [TypeError: fetch failed] { cause: [Error: AggregateError] }
}

tapz avatar Dec 05 '24 10:12 tapz

Thanks for the report.

There's an example project using HTTP on Vercel Edge Functions at https://github.com/neondatabase-labs/neon-vercel-http/blob/main/api/sites.ts, and deployed at https://neon-vercel-http-pn9w6ym59-jawjs-projects.vercel.app.

I just updated it to the latest driver version, and it seems to be working OK.

The first thing to check is probably just that the POSTGRES_URL_NON_POOLING environment variable is populated as expected. If that doesn't help, can you post a minimal test case to help us reproduce the issue?

jawj avatar Dec 05 '24 14:12 jawj

@jawj POSTGRES_URL_NON_POOLING works with Kysely, but with one-shot query directly using Neon does not work.

tapz avatar Dec 05 '24 15:12 tapz

I'm happy to investigate this but first I need something I can reproduce. As I mentioned, our own example app using http from Vercel Edge Functions is working fine.

jawj avatar Dec 05 '24 16:12 jawj

@jawj Maybe this is because I'm running Neon locally in Docker. Also, the query is quite complex and with Kysely executeQuery it tries to use CompressionStream, which is not available in Edge Runtime.

tapz avatar Dec 06 '24 12:12 tapz

A possible solution would be doing this

cliffordkleinsr avatar Feb 06 '25 05:02 cliffordkleinsr