fix: memory leak caused by many unclosed redis subscriptions (#750)

* fix: memory leak caused by many unclosed redis subscriptions

* chore: address pull request feedback
This commit is contained in:
Meier Lukas
2024-07-07 09:58:20 +02:00
committed by GitHub
parent 61cbb74d14
commit 998615fc11
7 changed files with 114 additions and 44 deletions

View File

@@ -9,16 +9,13 @@ import { createTRPCRouter, publicProcedure } from "../trpc";
export const logRouter = createTRPCRouter({
subscribe: publicProcedure.subscription(() => {
return observable<LoggerMessage>((emit) => {
let isConnectionClosed = false;
loggingChannel.subscribe((data) => {
if (isConnectionClosed) return;
const unsubscribe = loggingChannel.subscribe((data) => {
emit.next(data);
});
logger.info("A tRPC client has connected to the logging procedure");
return () => {
isConnectionClosed = true;
unsubscribe();
};
});
}),