diff --git a/src/hosts/host.commands.ts b/src/hosts/host.commands.ts index ab112a8..d803514 100644 --- a/src/hosts/host.commands.ts +++ b/src/hosts/host.commands.ts @@ -33,7 +33,7 @@ export function handleRegisterHost(hostRepository: HostRepository) { ); // TODO: Manage this via repo in `host.ts` or smth - NorayEvents.on("connection-close", (closed) => { + const onConnectionClose = (closed: Bun.Socket) => { if (closed !== socket) return; log.info( @@ -42,7 +42,10 @@ export function handleRegisterHost(hostRepository: HostRepository) { ); hostRepository.removeItem(host); activeHostsGauge.dec(); - }); + + NorayEvents.off("connection-close", onConnectionClose); + }; + NorayEvents.on("connection-close", onConnectionClose); }); }; }