plugins: finish unloading even if exports.unload crashes
Massimo Melina committed
Jun 21, 2024 at 11:38 UTC
5eaf68c352984e28d0ddf8290ae75a9334ca084e
1 file changed
+5
-7
src/plugins.ts
+5
-7
@@ -237,15 +237,13 @@ export class Plugin implements CommonPluginInterface {
237
if (!this.started) return
238
this.started = null
239
const { id } = this
240
- try {
241
- await this.data?.unload?.()
242
- await this.onUnload()
243
- if (!reloading && id !== SERVER_CODE_ID) // we already printed 'reloading'
244
- console.log('unloaded plugin', id)
245
- }
240
+ try { await this.data?.unload?.() }
241
catch(e) {
242
console.log('error unloading plugin', id, String(e))
243
}
244
+ await this.onUnload()
245
+ if (!reloading && id !== SERVER_CODE_ID) // we already printed 'reloading'
246
+ console.log('unloaded plugin', id)
247
if (this.data)
248
this.data.unload = undefined
249
}
@@ -458,7 +456,7 @@ function watchPlugin(id: string, path: string) {
456
457
const plugin = new Plugin(id, folder, pluginData, async () => {
458
unwatch()
461
- await Promise.allSettled(dbs.map(x => x.flush()))
459
+ await Promise.allSettled(dbs.map(x => x.close()))
460
dbs.length = 0
461
})
462
if (alreadyRunning)