fix: add app shutdown cleanup for port forward processes
Some checks failed
Test / frontend-tests (pull_request) Successful in 1m32s
Test / frontend-typecheck (pull_request) Successful in 1m34s
PR Review Automation / review (pull_request) Successful in 3m28s
Test / rust-fmt-check (pull_request) Failing after 11m18s
Test / rust-clippy (pull_request) Successful in 13m0s
Test / rust-tests (pull_request) Successful in 14m38s

- Add shutdown_port_forwards() Rust command to kill all child processes
- Add shutdownPortForwardsCmd() frontend command wrapper
- Add cleanup effect in App.tsx to call shutdown on unmount
- All port forward child processes now killed on app exit
This commit is contained in:
Shaun Arman 2026-06-06 18:48:52 -05:00
parent c53cfdd84f
commit b6453b0f75
2 changed files with 18 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect, useRef } from "react";
import { Routes, Route, NavLink, useLocation } from "react-router-dom"; import { Routes, Route, NavLink, useLocation } from "react-router-dom";
import { import {
Home, Home,
@ -17,7 +17,7 @@ import {
FileCode, FileCode,
} from "lucide-react"; } from "lucide-react";
import { useSettingsStore } from "@/stores/settingsStore"; import { useSettingsStore } from "@/stores/settingsStore";
import { getAppVersionCmd, loadAiProvidersCmd, testProviderConnectionCmd } from "@/lib/tauriCommands"; import { getAppVersionCmd, loadAiProvidersCmd, testProviderConnectionCmd, shutdownPortForwardsCmd } from "@/lib/tauriCommands";
import Dashboard from "@/pages/Dashboard"; import Dashboard from "@/pages/Dashboard";
import NewIssue from "@/pages/NewIssue"; import NewIssue from "@/pages/NewIssue";
@ -56,12 +56,25 @@ export default function App() {
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);
const [appVersion, setAppVersion] = useState(""); const [appVersion, setAppVersion] = useState("");
const { theme, setTheme, setProviders, getActiveProvider } = useSettingsStore(); const { theme, setTheme, setProviders, getActiveProvider } = useSettingsStore();
const cleanupDone = useRef(false);
void useLocation(); void useLocation();
useEffect(() => { useEffect(() => {
getAppVersionCmd().then(setAppVersion).catch(() => {}); getAppVersionCmd().then(setAppVersion).catch(() => {});
}, []); }, []);
// Cleanup port forwards on app unmount
useEffect(() => {
return () => {
if (!cleanupDone.current) {
cleanupDone.current = true;
void shutdownPortForwardsCmd().catch((err) => {
console.error("Failed to shutdown port forwards:", err);
});
}
};
}, []);
// Load providers and auto-test active provider on startup // Load providers and auto-test active provider on startup
useEffect(() => { useEffect(() => {
const initializeProviders = async () => { const initializeProviders = async () => {

View File

@ -788,3 +788,6 @@ export const deletePortForwardCmd = (id: string) =>
export const listPortForwardsCmd = () => export const listPortForwardsCmd = () =>
invoke<PortForwardResponse[]>("list_port_forwards"); invoke<PortForwardResponse[]>("list_port_forwards");
export const shutdownPortForwardsCmd = () =>
invoke<void>("shutdown_port_forwards");