Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

fix:The database connection is not closed during the catch block #1707

Open KotoriMinami opened 1 year ago

KotoriMinami commented 1 year ago

If this instance is not closed, it will result in the occupation of the database file.

When subsequent calls to setUpWithMigrations or setUpWithSchema reach the execution of unsafeDestroyEverything, https://github.com/Nozbe/WatermelonDB/blob/62774d5ebc4aa9ed6a2f61c8d4e795b32322cec6/src/adapters/sqlite/index.js#L144 https://github.com/Nozbe/WatermelonDB/blob/62774d5ebc4aa9ed6a2f61c8d4e795b32322cec6/src/adapters/sqlite/index.js#L195 Due to the old instance not closing the connection, even though the connection of the new instance is closed, an error resource busy or locked still occurs when executing fs.unlinkSync

This fixes https://github.com/Nozbe/WatermelonDB/issues/1705

radex commented 6 months ago

Thanks for the fix @KotoriMinami, but tests no longer pass after this