Connection failed, fetch failed.

I am trying to use drizzle (with planetscale drivers) to connect to a local mysql server but i consistantly get errors like HANDSHAKE_NO_SSL_SUPPORT & ERR_SSL_WRONG_VERSION_NUMBER
⨯ TypeError: fetch failed
at async login (./src/lib/auth/actions.ts:64:26)
Cause: [Error: 405CB710AC720000:error:0A00010B:SSL routines:tls_validate_record_header:wrong version number:ssl/record/methods/tlsany_meth.c:80:
] {
library: 'SSL routines',
reason: 'wrong version number',
code: 'ERR_SSL_WRONG_VERSION_NUMBER'
}
⨯ TypeError: fetch failed
at async login (./src/lib/auth/actions.ts:64:26)
Cause: [Error: 405CB710AC720000:error:0A00010B:SSL routines:tls_validate_record_header:wrong version number:ssl/record/methods/tlsany_meth.c:80:
] {
library: 'SSL routines',
reason: 'wrong version number',
code: 'ERR_SSL_WRONG_VERSION_NUMBER'
}
Do note that this issue persists no matter what SQL db i use. MariaDB, Mysql, Sqlite, Sqlite3 doesn't matter. I hate discords new formatting.
23 Replies
Mark
Mark7mo ago
This is my drizzle configuration.
import { type Config } from "drizzle-kit";

import { env } from "@/env";
import { DATABASE_PREFIX } from "@/lib/constants";

export default {
schema: "./src/server/db/schema.ts",
out: "./drizzle",
driver: "mysql2",
dbCredentials: {
connectionString: env.DATABASE_URL,
},
tablesFilter: [`${DATABASE_PREFIX}_*`],
} satisfies Config;
import { type Config } from "drizzle-kit";

import { env } from "@/env";
import { DATABASE_PREFIX } from "@/lib/constants";

export default {
schema: "./src/server/db/schema.ts",
out: "./drizzle",
driver: "mysql2",
dbCredentials: {
connectionString: env.DATABASE_URL,
},
tablesFilter: [`${DATABASE_PREFIX}_*`],
} satisfies Config;
Connection looks like this.
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { Connection } from "@planetscale/database";

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

export const connection = new Connection({ url: env.DATABASE_URL });

export const db = drizzle(connection, { schema });
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { Connection } from "@planetscale/database";

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

export const connection = new Connection({ url: env.DATABASE_URL });

export const db = drizzle(connection, { schema });
And the conncetionstring looks like this. mysql://MariaInterface:MARIADB@localhost:3306/lucia?ssl={"rejectUnauthorized":false}
Mykhailo
Mykhailo7mo ago
Hello, @Mark! I did research and I think this issue is not related to drizzle. It might be with your server setup. https://github.com/lbdremy/solr-node-client/issues/362
GitHub
{ library: 'SSL routines', function: 'ssl3_get_record', reaso...
I am using solr 8.11. behingd a nginx server at digitalocean on ubuntu 20.00. trying to run the code: // Use var solr = require('solr-client') in your code var solr = require('solr-clie...
Mark
Mark7mo ago
Weird, this shouldn't matter though, unless drizzle or the db for some reason wants a TLS / HTTPS connection. I have previously been able to use drizzle in other projects for DB access without issues, nor this TLS issue. I got kind of confused with that issue, are they implying that the mysql (MariaDB in this case) server got incorrectly set up? I combed through the project, there is no mentions of HTTPS / TLS connections in the code, i am unsure what the cause is anymore.
Mykhailo
Mykhailo7mo ago
Am I right that you are trying to connect to MariaDB using planetscale drivers?
Mark
Mark7mo ago
Yes. The example project i use has a planetscale config.
Mykhailo
Mykhailo7mo ago
Honestly, I am not familiar with MariaDB, but as far as I know, drizzle doesn't support MariaDB now. https://github.com/drizzle-team/drizzle-orm/issues/203
Mark
Mark7mo ago
MariaDB and Mysql are pretty similar, MariaDB has all the stuff that mysql has for dependancy reasons. Either way that doesn't matter as stated in my first message. I've used Mysql, Maria, sqlite, no difference. I looked for issues about this for both maria and mysql, both turned up nearly nothing. I saw a post that said to use Host, username and password in the connect code. However that turned up nothing, it works sure (No errors about the code itself) but the SSL issues still occur.
Mykhailo
Mykhailo7mo ago
Ok, did you test with other drivers? For example mysql2?
Mark
Mark7mo ago
With drizzle db:push drizzle-kit push:mysql I get the error "HANDSHAKE_NO_SUPPORT" which is unlikely to happen in the first place. There is SSL support but is likely a bug with something else. When i run SHOW VARIABLES WHERE "%SSL%"; I get this:
+---------------------+---------------------------+
| Variable_name | Value |
+---------------------+---------------------------+
| have_openssl | YES |
| have_ssl | DISABLED |
| ssl_ca | |
| ssl_capath | |
| ssl_cert | |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | |
| version_ssl_library | OpenSSL 3.2.1 30 Jan 2024 |
+---------------------+---------------------------+
+---------------------+---------------------------+
| Variable_name | Value |
+---------------------+---------------------------+
| have_openssl | YES |
| have_ssl | DISABLED |
| ssl_ca | |
| ssl_capath | |
| ssl_cert | |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | |
| version_ssl_library | OpenSSL 3.2.1 30 Jan 2024 |
+---------------------+---------------------------+
Give me a sec, i will answer your question in a bit Yes, i have tried mysql2. that is how i get the HANDSHAKE_NO_SUPPORT error.
import mysql from "mysql2/promise";
import { drizzle } from "drizzle-orm/mysql2";
import { migrate } from "drizzle-orm/mysql2/migrator";

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

export async function runMigrate() {
const connection = await mysql.createConnection(env.DATABASE_URL);
const db = drizzle(connection, { schema, mode: "planetscale" });

console.log("⏳ Running migrations...");

const start = Date.now();

await migrate(db, { migrationsFolder: "drizzle" });

const end = Date.now();

console.log(`✅ Migrations completed in ${end - start}ms`);

process.exit(0);
}

runMigrate().catch((err) => {
console.error("❌ Migration failed");
console.error(err);
process.exit(1);
});
import mysql from "mysql2/promise";
import { drizzle } from "drizzle-orm/mysql2";
import { migrate } from "drizzle-orm/mysql2/migrator";

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

export async function runMigrate() {
const connection = await mysql.createConnection(env.DATABASE_URL);
const db = drizzle(connection, { schema, mode: "planetscale" });

console.log("⏳ Running migrations...");

const start = Date.now();

await migrate(db, { migrationsFolder: "drizzle" });

const end = Date.now();

console.log(`✅ Migrations completed in ${end - start}ms`);

process.exit(0);
}

runMigrate().catch((err) => {
console.error("❌ Migration failed");
console.error(err);
process.exit(1);
});
I am not 100% sure if the "have_ssl" can be a cause, but i would assume so. I have used a db explorer like dbeaver and it connects without any issues without TLS, SSL or anything like that.
Mykhailo
Mykhailo7mo ago
interesting, so you have this issue will all db (MySQL,SQLite)
Mark
Mark7mo ago
Yes. sqlite i am a bit unsure of, i will have to check if i actually did use it. It will be weird if that one woud fail considering its not meant to really be on the web due to the fact that you cannot secure it with user auth (at least to my knowledge) Ima see if i can change the use_ssl to yes and if it resolves anything.
Mykhailo
Mykhailo7mo ago
I will try to investigate tomorrow, I haven’t faced this issue before
Mark
Mark7mo ago
It doesn't seem to be very common.
Mark
Mark7mo ago
Okay, moment of truth.
No description
Mark
Mark7mo ago
Nope, same issue. Wait hold on, i am getting a breakthrough. wait so. i go back to:
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

const connection = await mysql.createConnection({
host: "host",
user: "user",
database: "database",
...
});

const db = drizzle(connection);
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

const connection = await mysql.createConnection({
host: "host",
user: "user",
database: "database",
...
});

const db = drizzle(connection);
It kind of semi works but it complains about the await? ⨯ SyntaxError: await is only valid in async functions and the top level bodies of modules at (action-browser)/./src/server/db/index.ts (/home/mark/next-lucia-auth/.next/server/app/(auth)/login/page.js:893:1) at __webpack_require__ (/home/mark/next-lucia-auth/.next/server/webpack-runtime.js:33:42) at eval (./src/lib/auth/index.ts:10:68) at (action-browser)/./src/lib/auth/index.ts (/home/mark/next-lucia-auth/.next/server/app/(auth)/login/page.js:772:1) at __webpack_require__ (/home/mark/next-lucia-auth/.next/server/webpack-runtime.js:33:42) at eval (./src/lib/auth/actions.ts:21:67) at (action-browser)/./src/lib/auth/actions.ts (/home/mark/next-lucia-auth/.next/server/app/(auth)/login/page.js:761:1) at Function.__webpack_require__ (/home/mark/next-lucia-auth/.next/server/webpack-runtime.js:33:42) printing the connection results in this.
Connection {
session: null,
config: {
url: 'mysql://MariaInterface:MARIADB@127.0.0.1:3306/lucia?ssl=strict',
fetch: [AsyncFunction (anonymous)] {
__nextGetStaticStore: [Function (anonymous)],
__nextPatched: true
},
username: 'MariaInterface',
password: 'MARIADB',
host: '127.0.0.1'
},
url: 'https://127.0.0.1:3306/lucia'
}
Connection {
session: null,
config: {
url: 'mysql://MariaInterface:MARIADB@127.0.0.1:3306/lucia?ssl=strict',
fetch: [AsyncFunction (anonymous)] {
__nextGetStaticStore: [Function (anonymous)],
__nextPatched: true
},
username: 'MariaInterface',
password: 'MARIADB',
host: '127.0.0.1'
},
url: 'https://127.0.0.1:3306/lucia'
}
So it seems to be valid, problem is that still says wrong version number. Seems like drizzle gets all of the required info like username, password and so on from the conncetionurl, which is nice to know but confusing on why it fails.
Want results from more Discord servers?
Add your server