sidorares / sidorares/node-mysql2
Query stops when the app is wrapped with async wrapper
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
It can only be reproduced with the following usage.
I have a cli application that is using mysql2/promise
const app = new AppController(...)//...takes in all the db stuffs
(async () => {
tempDb = createPool({
host: process.env.TEMP_MYSQL_HOST,
user: process.env.TEMP_MYSQL_USER,
password: process.env.TEMP_MYSQL_PASS,
database: process.env.TEMP_MYSQL_DB,
});
console.log(await tempDb.query("SELECT 1"); // this will stop the app from running and exited 0(zero)
await app.run();
})();
It will only work if I use TSC to compile the app into commonjs with no async await but only promise by writing as
const app = new AppController(...)//...takes in all the db stuffs
await app.run(); //queries inside will work and returns correctly
May I know why?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the mysql2/promise entry point and reproduce the supplied CLI example, comparing the async-wrapper and compiled CommonJS cases. Trace the query call and process lifetime around app.run; done when the query and app.run complete instead of the process exiting early, with a regression test covering the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js, typescript
- Domain
- backend, cli, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100