planetscale / database-js

A Fetch API-compatible PlanetScale database driver
https://planetscale.com/docs/tutorials/planetscale-serverless-driver
Apache License 2.0
1.16k stars 32 forks source link

Type error fetch failed #142

Open statusunknown418 opened 9 months ago

statusunknown418 commented 9 months ago

getting this very weird issue with newly created proejct, unable to query anything.

{
  e: TypeError: fetch failed
      at Object.fetch (node:internal/deps/undici/undici:11576:11)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async postJSON (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@planetscale+database@1.11.0/node_modules/@planetscale/database/dist/index.js:128:22)
      at async Connection.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@planetscale+database@1.11.0/node_modules/@planetscale/database/dist/index.js:86:23)
      at async PlanetScalePreparedQuery.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0/node_modules/drizzle-orm/planetscale-serverless/index.mjs:31:26)
      at async eval (webpack-internal:///(api)/./src/server/api/routers/example.ts:19:23)
      at async resolveMiddleware (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/index.mjs:420:30)
      at async callRecursive (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/index.mjs:456:32)
      at async callRecursive (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/index.mjs:456:32)
      at async resolve (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/index.mjs:486:24)
      at async inputToProcedureCall (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/resolveHTTPResponse-68c8befb.mjs:46:22)
      at async Promise.all (index 0)
      at async resolveHTTPResponse (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/resolveHTTPResponse-68c8befb.mjs:182:37)
      at async file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/nodeHTTPRequestHandler-dbf26ba2.mjs:67:9
      at async file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@trpc+server@10.38.5/node_modules/@trpc/server/dist/adapters/next.mjs:44:9 {
    cause: [Error: 0093F4DB01000000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:355:
    ] {
      library: 'SSL routines',
      reason: 'wrong version number',
      code: 'ERR_SSL_WRONG_VERSION_NUMBER'
    }
  }
}
[next-auth][error][adapter_error_getSessionAndUser] 
https://next-auth.js.org/errors#adapter_error_getsessionanduser fetch failed {
  message: 'fetch failed',
  stack: 'TypeError: fetch failed\n' +
    '    at Object.fetch (node:internal/deps/undici/undici:11576:11)\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '    at async postJSON (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@planetscale+database@1.11.0/node_modules/@planetscale/database/dist/index.js:128:22)\n' +
    '    at async Connection.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@planetscale+database@1.11.0/node_modules/@planetscale/database/dist/index.js:86:23)\n' +
    '    at async PlanetScalePreparedQuery.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0/node_modules/drizzle-orm/planetscale-serverless/index.mjs:31:26)\n' +
    '    at async getSessionAndUser (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@auth+drizzle-adapter@0.3.3/node_modules/@auth/drizzle-adapter/lib/mysql.js:90:37)',
  name: 'TypeError'
}
[next-auth][error][SESSION_ERROR] 
https://next-auth.js.org/errors#session_error fetch failed TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11576:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async postJSON (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@planetscale+database@1.11.0/node_modules/@planetscale/database/dist/index.js:128:22)
    at async Connection.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@planetscale+database@1.11.0/node_modules/@planetscale/database/dist/index.js:86:23)
    at async PlanetScalePreparedQuery.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0/node_modules/drizzle-orm/planetscale-serverless/index.mjs:31:26)
    at async getSessionAndUser (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@auth+drizzle-adapter@0.3.3/node_modules/@auth/drizzle-adapter/lib/mysql.js:90:37) {
  name: 'GetSessionAndUserError',
  code: undefined
}
mattrobenolt commented 9 months ago

Can you share a redacted version of your configuration? This error is fundamentally an SSL issue. So maybe trying to use http when we require https, or the TLS version is too low, which would be quite a bit odd. We require TLS 1.2+.

statusunknown418 commented 9 months ago

how do I update TLS? this is my db/index.ts file

import { connect } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";

// create the connection
export const connection = connect({
  url: process.env.DATABASE_URL!,
});

export const db = drizzle(connection);
mattrobenolt commented 9 months ago

It's not typically something you do directly and comes from the underlying networking libraries of the runtime.

Where are you running this and can you share a redacted version of that DATABASE_URL?

statusunknown418 commented 9 months ago

running locally, using drizzle:

mattrobenolt commented 9 months ago

Aha, so that's what I was looking for. Using port 3306 doesn't work. We should auto fix this in database-js, but this connection string is not correct here.

You'd want something like this:

DATABASE_URL=https://user:pass@aws.connect.psdb.cloud

I'll open up and issue about ignoring the 3306 part since that will never work.

statusunknown418 commented 9 months ago

right thanks a lot!, I also tried using USERNAME, HOST and PASSWORD instead, like this:

import { env } from "~/env.mjs";
import * as schema from "./schema";

import { connect } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";

// create the connection
const connection = connect({
  host: env.DATABASE_HOST,
  username: env.DATABASE_USERNAME,
  password: env.DATABASE_PASSWORD,
});

export const db = drizzle(connection, { schema });

and this seems to work nicely too

statusunknown418 commented 9 months ago

this issue had me blocked for hours lol

mattrobenolt commented 9 months ago

When you had to split up, was :3306 inside DATABASE_HOST too? If so, same issue.

statusunknown418 commented 9 months ago

actually not, I used the credentials generated from pscale cli and it only included the name aws.psdb.cloud.com

jln13x commented 8 months ago

running into that issue using prisma/kysely and the planetscale cli proxy that allows me to connect to mysql://127.0.0.1/foo

any way around it?