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

Writing to Sqlite database causes process to hang while using TypeORM #12193

Open
davidstevens37 opened this issue Jun 27, 2024 · 1 comment
Open
Labels
bug Something isn't working needs triage

Comments

@davidstevens37
Copy link

What version of Bun is running?

1.1.17+bb66bba1b

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

While using TypeORM, the operations seem to "work" however after a certain point the process hangs and does not finish. This is quickly visible iterating and bulk inserting records into the sqlite database using TypeORM.

typeorm-example.ts:

import 'reflect-metadata';
import { DataSource, BaseEntity, Entity, PrimaryGeneratedColumn, Column } from "typeorm";

@Entity({ name: 'test' })
class Item extends BaseEntity {
    @PrimaryGeneratedColumn()
    id!: number;

    @Column()
    name!: string;
}

const AppDataSource = new DataSource({
    type: 'sqlite',
    database: 'db.sqlite',
    synchronize: true,
    enableWAL: true,
    entities: [Item],
    migrations: [],
    subscribers: [],
});
await AppDataSource.initialize();
await Item.delete({});
const start = Date.now();
let count = 0;

while (count < 50000) {
    const items = Array.from({ length: 1000 }, (_, i) => Item.create({ name: 'test' }));
    await Item.save(items);
    count = await Item.count();
    console.log(count);
}
console.log('Time:', Date.now() - start);
await AppDataSource.close();

tsconfig:

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "NodeNext",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}

What is the expected behavior?

the output of the script above should be 50 console.logs incrementing by 1000 each time (the number of records), followed by a Time taken.

while either using ts-node or transpiring to to a javascript file and running node dist/typeorm-example.js the output results in the expected.

> node --loader ts-node/esm typeorm-example.ts
1000
2000
3000
...
...
...
48000
49000
50000
Time: 2686

What do you see instead?

while executing the typescript file with bun bun run typeorm-example.ts or the transpiled javascript (using tsc or bun) with bun bun run dist/typeorm-example.js, the output begins as expected, but the freezes and does not print more than X iterations. Seems it gets farther when running the transpiled version instead of the TS directly.

With the transpiled JS, it gets 9, 11, or 16 iterations before freezing. With the TS directly, it usually chokes around 3 or 4 iterations. Once it stops, it makes no further progress, even if left for minutes.

> bun run typeorm-example.ts
1000
2000
3000

Additional information

No response

@davidstevens37 davidstevens37 added bug Something isn't working needs triage labels Jun 27, 2024
@Jarred-Sumner
Copy link
Collaborator

I'm able to reproduce a crash when sqlite3 is not installed. The crash becomes an error in #12246 (likely due to WebKit/WebKit#30298), but I'm not yet able to reproduce the hanging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants