bun icon indicating copy to clipboard operation
bun copied to clipboard

MySQL transaction is hanging/freezing on Windows.

Open thinhbuzz opened this issue 2 weeks ago โ€ข 3 comments

What version of Bun is running?

1.3.4+5eb2145b3

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

Run bun run demo.ts on both Windows and Linux to compare.

CREATE TABLE `countries` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `code` varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `countries_code_unique` (`code`)
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
import { SQL } from "bun";

const isWin = process.platform === "win32";

const sql = new SQL(`mysql://root:root@${isWin ? "localhost" : "database"}:3306/database_name`);

console.log(new Date().toISOString(), "start phase 1");
const r = await sql.begin(async (tx) => {
  const data = { name: "Name 11", code: "CODE_" + Math.random().toString().slice(2) };
  console.log(new Date().toISOString(), "phase 1 data", data);
  await tx.unsafe("INSERT INTO countries (name,code) VALUES (?, ?)", [data.name, data.code]);
  const data2 = { name: "Name 12", code: "CODE_" + Math.random().toString().slice(2) };
  console.log(new Date().toISOString(), "pharse 1 data2", data2);
  await tx.unsafe("INSERT INTO countries (name,code) VALUES (?, ?)", [data2.name, data2.code]);
});
console.log(new Date().toISOString(), "phase 1 result", JSON.stringify(r, null, 2));

console.log(new Date().toISOString(), "end phase 1");

console.log(new Date().toISOString(), "start phase 2");
const r2 = await sql.begin(async (tx) => {
  const data = { name: "Name 21", code: "CODE_" + Math.random().toString().slice(2) };
  console.log(new Date().toISOString(), "pharse 2 data", data);
  await tx.unsafe("INSERT INTO countries (name,code) VALUES (?, ?)", [data.name, data.code]);
  const data2 = { name: "Name 22", code: "CODE_" + Math.random().toString().slice(2) };
  console.log(new Date().toISOString(), "pharse 2 data2", data2);
  await tx.unsafe("INSERT INTO countries (name,code) VALUES (?, ?)", [data2.name, data2.code]);
});
console.log(new Date().toISOString(), "phase 2 result", JSON.stringify(r2, null, 2));

console.log(new Date().toISOString(), "end phase 2");

What is the expected behavior?

On Linux, both transactions complete perfectly.: Linux 6.10.4-linuxkit x86_64 unknown (Bun docker image)

2025-12-17T12:52:52.697Z start phase 1
2025-12-17T12:52:52.701Z phase 1 data {
  name: "Name 11",
  code: "CODE_8214427609856949",
}
2025-12-17T12:52:52.702Z pharse 1 data2 {
  name: "Name 12",
  code: "CODE_5163620021901038",
}
2025-12-17T12:52:52.704Z phase 1 result undefined
2025-12-17T12:52:52.704Z end phase 1
2025-12-17T12:52:52.704Z start phase 2
2025-12-17T12:52:52.705Z pharse 2 data {
  name: "Name 21",
  code: "CODE_6890230682582414",
}
2025-12-17T12:52:52.705Z pharse 2 data2 {
  name: "Name 22",
  code: "CODE_5995857281399145",
}
2025-12-17T12:52:52.707Z phase 2 result undefined
2025-12-17T12:52:52.707Z end phase 2

What do you see instead?

On Windows, a second transaction cannot be started.: Microsoft Windows NT 10.0.26100.0 x64

2025-12-17T12:52:58.074Z start phase 1
2025-12-17T12:52:58.087Z phase 1 data {
  name: "Name 11",
  code: "CODE_8113148915331181",
}
2025-12-17T12:52:58.088Z pharse 1 data2 {
  name: "Name 12",
  code: "CODE_4357247629423284",
}
2025-12-17T12:52:58.092Z phase 1 result undefined
2025-12-17T12:52:58.092Z end phase 1
2025-12-17T12:52:58.092Z start phase 2

Additional information

No response

thinhbuzz avatar Dec 17 '25 13:12 thinhbuzz

๐Ÿ“ CodeRabbit Plan Mode

Generate an implementation plan and prompts that you can use with your favorite coding agent.

  • [ ] Create Plan
Examples
You can configure auto-planning by selecting labels in the issue_enrichment configuration.

๐Ÿ”— Related PRs

oven-sh/bun#22438 - fix(Bun.SQL) test failure [merged] oven-sh/bun#22696 - fix(Bun.SQL) fix MySQL execution on windows [merged] oven-sh/bun#23873 - fix(MySQL) ref and status usage [merged]

๐Ÿ‘ค Suggested Assignees


๐Ÿงช Issue enrichment is currently in open beta.

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

๐Ÿ’ฌ Have feedback or questions? Drop into our discord or schedule a call!

coderabbitai[bot] avatar Dec 17 '25 13:12 coderabbitai[bot]

Tested with Bun 1.3.5-canary.48+fa5a5bbe5 but still encountered the same error.

thinhbuzz avatar Dec 17 '25 13:12 thinhbuzz