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:
@@ -27,19 +27,15 @@ export const appRouter = createTRPCRouter({
|
||||
const pingResult = await sendPingRequestAsync(input.url);
|
||||
|
||||
return observable<{ url: string; statusCode: number } | { url: string; error: string }>((emit) => {
|
||||
let isConnectionClosed = false;
|
||||
|
||||
emit.next({ url: input.url, ...pingResult });
|
||||
pingChannel.subscribe((message) => {
|
||||
if (isConnectionClosed) return;
|
||||
|
||||
const unsubscribe = pingChannel.subscribe((message) => {
|
||||
// Only emit if same url
|
||||
if (message.url !== input.url) return;
|
||||
emit.next(message);
|
||||
});
|
||||
|
||||
return () => {
|
||||
isConnectionClosed = true;
|
||||
unsubscribe();
|
||||
void pingUrlChannel.removeAsync(input.url);
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user