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:
@@ -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();
|
||||
};
|
||||
});
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user