Skip to content

Commit

Permalink
close connections when organization change
Browse files Browse the repository at this point in the history
  • Loading branch information
CurryYangxx committed Jan 9, 2025
1 parent 14a48cb commit 8f4715d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/insomnia/src/ui/hooks/use-close-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useInsomniaTabContext } from '../context/app/insomnia-tab-context';
import uiEventBus from '../eventBus';

// this hook is use for control when to close connections(websocket & SSE & grpc stream & graphql subscription)
export const useCloseConnection = () => {
export const useCloseConnection = ({ organizationId }: { organizationId: string }) => {

const closeConnectionById = async (id: string) => {
if (isGrpcRequestId(id)) {
Expand Down Expand Up @@ -59,4 +59,13 @@ export const useCloseConnection = () => {
uiEventBus.off('CHANGE_ACTIVE_ENV', handleActiveEnvironmentChange);
};
}, [handleTabClose, handleActiveEnvironmentChange]);

// close all connections when organizationId change
useEffect(() => {
return () => {
window.main.webSocket.closeAll();
window.main.grpc.closeAll();
window.main.curl.closeAll();
};
}, [organizationId]);
};
4 changes: 3 additions & 1 deletion packages/insomnia/src/ui/routes/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ export const Debug: FC = () => {
},
});

useCloseConnection();
useCloseConnection({
organizationId,
});

const isRealtimeRequest =
activeRequest &&
Expand Down

0 comments on commit 8f4715d

Please sign in to comment.