fix(mysql): unreference all connections so that the process can exit cleanly
In a NodeJS environment it will just work as before, but in a Bun environment it will make the "forced exit" error message disappear and remove the 10 s waiting period when migrations are done.
This commit is contained in:
parent
e7ec75d9e1
commit
198aa545eb
2 changed files with 15 additions and 0 deletions
|
|
@ -171,6 +171,12 @@ export const createMysqlStorage = ({ table = defaultTable, connection }: MysqlSt
|
|||
async initializeStorage() {
|
||||
const pool = getPool(connection);
|
||||
|
||||
pool.on('connection', (connection) => {
|
||||
// @ts-expect-error stream is not in the types but it's there
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
connection.stream.unref();
|
||||
});
|
||||
|
||||
await pool.query('SELECT 1');
|
||||
|
||||
try {
|
||||
|
|
@ -268,6 +274,10 @@ export const createMysqlLoader = ({ connection }: MysqlLoaderOptions): LoaderPlu
|
|||
const contents = await fs.readFile(migration.filePath, 'utf8');
|
||||
const conn = await getConnection(connection);
|
||||
|
||||
// @ts-expect-error the connection is not in the types but it's there
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
conn.connection.stream.unref();
|
||||
|
||||
try {
|
||||
await conn.query(contents);
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue