Skip to content

mariadb-connector-nodejs connection timeout with Cloudflare Hyperdrive #322

@medz

Description

@medz

mariadb-connector-nodejs connection timeout with Cloudflare Hyperdrive

Summary

mariadb-connector-nodejs v3.4.2 consistently fails with connection timeouts when connecting through Cloudflare Hyperdrive, while mysql2 v3.14.1 works perfectly with the same Hyperdrive configuration.

Environment

  • mariadb: 3.4.2
  • mysql2: 3.14.1 (for comparison)
  • Platform: Cloudflare Workers
  • Database Proxy: Cloudflare Hyperdrive
  • Database: MySQL 8.0

Problem

When connecting to MySQL through Cloudflare Hyperdrive proxy, mariadb-connector-nodejs times out consistently, while mysql2 connects successfully using the same Hyperdrive binding.

Reproduction

mysql2 (works with Hyperdrive)

import { createConnection } from 'mysql2/promise';

const connection = await createConnection({
  host: env.DATABASE.host, // Hyperdrive proxy host
  user: env.DATABASE.user, // Hyperdrive proxy user
  password: env.DATABASE.password, // Hyperdrive proxy password
  database: env.DATABASE.database,
  port: env.DATABASE.port, // Hyperdrive proxy port
  connectTimeout: 10000,
});

const result = await connection.query('SHOW TABLES');
// ✅ Connects instantly through Hyperdrive

mariadb (fails with Hyperdrive)

import mariadb from 'mariadb';

const connection = await mariadb.createConnection({
  host: env.DATABASE.host, // Same Hyperdrive proxy host
  user: env.DATABASE.user, // Same Hyperdrive proxy user
  password: env.DATABASE.password, // Same Hyperdrive proxy password
  database: env.DATABASE.database,
  port: env.DATABASE.port, // Same Hyperdrive proxy port
  connectTimeout: 10000,
});

const result = await connection.query('SHOW TABLES');
// ❌ Times out after exactly 10 seconds

Cloudflare Configuration

// wrangler.jsonc
{
  "compatibility_flags": ["nodejs_compat"],
  "hyperdrive": [{ "binding": "DATABASE", "id": "your-hyperdrive-id" }],
}

Error

Error: Connection timeout after 10000ms

The timeout occurs precisely at the connectTimeout value when connecting through Hyperdrive proxy.

Key Evidence

  • Same Hyperdrive binding: Both libraries use identical env.DATABASE.* values
  • mysql2 works: Proves Hyperdrive proxy is functioning correctly
  • mariadb fails: Times out consistently at exact connectTimeout duration
  • Environment-specific: Issue occurs specifically with Hyperdrive proxy connections

Tested configurations

All fail with the same timeout when using Hyperdrive:

// Different timeout values
connectTimeout: 5000,   // times out after 5s
connectTimeout: 30000,  // times out after 30s
connectTimeout: 60000,  // times out after 60s

// Connection pool with Hyperdrive
const pool = mariadb.createPool({
  host: env.DATABASE.host,
  user: env.DATABASE.user,
  password: env.DATABASE.password,
  database: env.DATABASE.database,
  port: env.DATABASE.port,
  connectTimeout: 30000,
});
const conn = await pool.getConnection(); // times out

// SSL options with Hyperdrive
ssl: false,  // still times out
ssl: { rejectUnauthorized: false },  // still times out

Expected behavior

mariadb-connector-nodejs should connect successfully through Cloudflare Hyperdrive proxy, just like mysql2 does.

Additional info

  • mysql2 working proves Hyperdrive proxy configuration is correct
  • Same issue occurs across different Hyperdrive configurations
  • Problem is specific to mariadb + Hyperdrive combination
  • Cloudflare Workers with nodejs_compat enabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions