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

Error while working with 'better-sqlite3' #17255

Open
truongtom1993 opened this issue Feb 11, 2025 · 0 comments
Open

Error while working with 'better-sqlite3' #17255

truongtom1993 opened this issue Feb 11, 2025 · 0 comments
Labels
crash An issue that could cause a crash runtime windows An issue that is known to occur on Windows

Comments

@truongtom1993
Copy link

How can we reproduce the crash?

here is the code, it's working when i try with node
`
import Database from 'better-sqlite3';

async function createDatabaseAndInsertUsers() {
const db = new Database('server/database/sqlite.db', { verbose: console.log });

db.exec(`
CREATE TABLE IF NOT EXISTS user (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE,
  age INTEGER NOT NULL
)

`);

const users = generateRandomUsers(3);

const insertStmt = db.prepare('INSERT INTO user (name, email, age) VALUES (?, ?, ?)');

const insertUsers = db.transaction(users => {
	users.forEach(user => {
		insertStmt.run(user.name, user.email, user.age);
	});
});

insertUsers(users);
    const rows = db.prepare('SELECT * FROM user').all();
db.close(); 

}

function generateRandomUsers(count) {
const names = ['Alice', 'Bob', 'Charlie', 'David', 'Eve'];
const domains = ['example.com', 'test.com', 'demo.com'];
const users = [];

for (let i = 0; i < count; i++) {
	const name = names[Math.floor(Math.random() * names.length)];
	const email = `${name.toLowerCase()}${Math.floor(Math.random() * 100)}@${domains[Math.floor(Math.random() * domains.length)]}`;
	const age = Math.floor(Math.random() * 50) + 18;
	users.push({ name, email, age });
}

return users;

}
createDatabaseAndInsertUsers()
`

Relevant log output

$ bun server/api/createDb.js
107 |         return opts[p] || p;
108 |       })
109 |     );
110 |     tries.push(n);
111 |     try {
112 |       b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
                                                     ^
error: LoadLibrary failed: A dynamic link library (DLL) in
 code: "ERR_DLOPEN_FAILED"

      at bindings (D:\Project\Project_JS\Nitro\nitro-app\node_modules\bindings\bindings.js:112:48)
      at new Database (D:\Project\Project_JS\Nitro\nitro-app\node_modules\better-sqlite3\lib\database.js:48:29)
      at <anonymous> (D:\Project\Project_JS\Nitro\nitro-app\server\api\createDb.js:9:13)
      at createDatabaseAndInsertUsers (D:\Project\Project_JS\Nitro\nitro-app\server\api\createDb.js:7:44)
      at D:\Project\Project_JS\Nitro\nitro-app\server\api\createDb.js:60:1

Bun v1.2.2 (Windows x64)
============================================================
Bun v1.2.2 (c1708ea6) Windows x64
Windows v.win10_fe
CPU: sse42 avx avx2
Args: "C:\Users\dang_\.bun\bin\bun.exe" "server/api/createDb.js"
Features: jsc tsconfig(2) tsconfig_paths process_dlopen
Builtins: "bun:main" "node:fs" "node:path" "node:util" "node:util/types"
Elapsed: 227ms | User: 93ms | Sys: 31ms
RSS: 132.74MB | Peak: 132.74MB | Commit: 0.19GB | Faults: 32718

panic(main thread): Segmentation fault at address 0x7FF9811B9F50
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

Stack Trace (bun.report)

Bun v1.2.2 (c1708ea) on windows x86_64 [AutoCommand]

Segmentation fault at address 0x7FF9999B9F50

Features: tsconfig_paths, process_dlopen, jsc, tsconfig, tsconfig

Sentry Issue: BUN-8SR

@truongtom1993 truongtom1993 added the crash An issue that could cause a crash label Feb 11, 2025
@github-actions github-actions bot added runtime windows An issue that is known to occur on Windows labels Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash An issue that could cause a crash runtime windows An issue that is known to occur on Windows
Projects
None yet
Development

No branches or pull requests

1 participant