Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error fetch failed #142

Open
statusunknown418 opened this issue Oct 6, 2023 · 10 comments
Open

Type error fetch failed #142

statusunknown418 opened this issue Oct 6, 2023 · 10 comments

Comments

@statusunknown418
Copy link

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/@[email protected]/node_modules/@planetscale/database/dist/index.js:128:22)
      at async Connection.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@planetscale/database/dist/index.js:86:23)
      at async PlanetScalePreparedQuery.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/[email protected]_@[email protected]/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/@[email protected]/node_modules/@trpc/server/dist/index.mjs:420:30)
      at async callRecursive (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/index.mjs:456:32)
      at async callRecursive (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/index.mjs:456:32)
      at async resolve (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/index.mjs:486:24)
      at async inputToProcedureCall (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/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/@[email protected]/node_modules/@trpc/server/dist/resolveHTTPResponse-68c8befb.mjs:182:37)
      at async file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/nodeHTTPRequestHandler-dbf26ba2.mjs:67:9
      at async file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/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/@[email protected]/node_modules/@planetscale/database/dist/index.js:128:22)\n' +
    '    at async Connection.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@planetscale/database/dist/index.js:86:23)\n' +
    '    at async PlanetScalePreparedQuery.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/drizzle-orm/planetscale-serverless/index.mjs:31:26)\n' +
    '    at async getSessionAndUser (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/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/@[email protected]/node_modules/@planetscale/database/dist/index.js:128:22)
    at async Connection.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@planetscale/database/dist/index.js:86:23)
    at async PlanetScalePreparedQuery.execute (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/drizzle-orm/planetscale-serverless/index.mjs:31:26)
    at async getSessionAndUser (file:///Users/a3tech/Developer/personal_projects/remarkable/node_modules/.pnpm/@[email protected]/node_modules/@auth/drizzle-adapter/lib/mysql.js:90:37) {
  name: 'GetSessionAndUserError',
  code: undefined
}
@mattrobenolt
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

running locally, using drizzle:

  • Using the optimized connection from planetscale
DATABASE_URL=mysql://user:[email protected]:3306/toldyouso?ssl={"rejectUnauthorized": true}

@mattrobenolt
Copy link
Member

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:[email protected]

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

@statusunknown418
Copy link
Author

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
Copy link
Author

this issue had me blocked for hours lol

@mattrobenolt
Copy link
Member

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

@statusunknown418
Copy link
Author

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

@jln13x
Copy link

jln13x commented Oct 14, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants