Skip to content

"Error: read UNKNOWN" error when using TLS to connect to database using mysql2 #20293

@DMeechan

Description

@DMeechan

When using Deno 1.36.3 I get this Uncaught (in promise) Error: read UNKNOWN error when running the script below:

error: Uncaught (in promise) Error: read UNKNOWN
    at createConnection (file:///home/u/node-vs-deno-db-drivers/node_modules/.deno/mysql2@3.6.0/node_modules/mysql2/promise.js:253:31)
    at file:///home/u/node-vs-deno-db-drivers/mysql2.ts:12:28
    at file:///home/u/node-vs-deno-db-drivers/mysql2.ts:21:1

When using Deno 1.36.1 (which precedes #20120) I get an Uncaught Error: tlssock._start is not a function error when running the script:

error: Uncaught Error: tlssock._start is not a function
    at createConnection (file:///home/u/node-vs-deno-db-drivers/node_modules/.deno/mysql2@3.6.0/node_modules/mysql2/promise.js:253:31)
    at file:///home/u/node-vs-deno-db-drivers/mysql2.ts:12:28
    at file:///home/u/node-vs-deno-db-drivers/mysql2.ts:21:1

Given that the stack trace indicates the Error: read UNKNOWN error is being thrown from the same place as the Uncaught Error: tlssock._start is not a function error was, I'm thinking it may be a TLS-related issue in Deno.

I've tested the script below with Node v18.17.1 and it runs fine.

How to reproduce

Create mysql2.ts:

// Swap the commenting on these two lines if you're testing this on Node.js vs Deno
import { createConnection } from "npm:mysql2@^3.6.0/promise"; // For Deno
// import { createConnection } from "mysql2/promise"; // For Node.js

import { readFileSync } from "node:fs";
const cert = readFileSync("/etc/ssl/certs/ca-certificates.crt"); // I'm using Ubuntu - this certificate path may be different for your OS
const planetscaleMysqlUrl = "SOME_MYSQL_URL_HERE";

(async () => {
  const connection = await createConnection({
    uri: planetscaleMysqlUrl,
    ssl: { ca: cert },
  });

  const result = await connection.execute("SELECT 1");
  console.log(result);

  connection.end();
})();

In Deno

Run the script above using Deno 1.36.3: deno run -A mysql2.ts

In Node.js

Using v18.17.1:

  1. npm init -y
  2. Add "type": "module" to package.json
  3. npm install mysql2@3.6.0
  4. Copy or rename the file to .js (it's easier): cp mysql2.ts mysql2.js
  5. Swap the import comments on lines 2 and 3 of mysql2.js
  6. node mysql2.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlynode compat

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions