Skip to content

Commit 8041807

Browse files
fix: improve websocket and watcher cleanup handling (#3478)
1 parent 9764c05 commit 8041807

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/utils/dev.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ export async function startSocketServer(nuxt: Nuxt, options: ModuleOptions, mani
4343

4444
nuxt.hook('close', async () => {
4545
// Close WebSocket server
46-
await websocket?.close()
47-
await listener?.server?.close()
46+
if (websocket) {
47+
await websocket.close()
48+
}
49+
// Close listener server
50+
if (listener) {
51+
await listener.close()
52+
}
4853
})
4954
}
5055

@@ -211,8 +216,11 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest
211216
}
212217

213218
nuxt.hook('close', async () => {
214-
watcher.close()
215-
db.close()
219+
if (watcher) {
220+
watcher.removeAllListeners()
221+
watcher.close()
222+
db.close()
223+
}
216224
})
217225
}
218226

0 commit comments

Comments
 (0)