File tree Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -908,21 +908,44 @@ export const installedScriptsRouter = createTRPCRouter({
908908 // Check if the container config file still exists
909909 const checkCommand = `test -f "/etc/pve/lxc/${ scriptData . container_id } .conf" && echo "exists" || echo "not_found"` ;
910910
911+ // Await full command completion to avoid early false negatives
911912 const containerExists = await new Promise < boolean > ( ( resolve ) => {
912-
913+ let combinedOutput = '' ;
914+ let resolved = false ;
915+
916+ const finish = ( ) => {
917+ if ( resolved ) return ;
918+ resolved = true ;
919+ const out = combinedOutput . trim ( ) ;
920+ if ( out . includes ( 'exists' ) ) {
921+ resolve ( true ) ;
922+ } else if ( out . includes ( 'not_found' ) ) {
923+ resolve ( false ) ;
924+ } else {
925+ // Unknown output; treat as not found but log for diagnostics
926+ console . warn ( `cleanupOrphanedScripts: unexpected output for ${ String ( scriptData . script_name ) } (${ String ( scriptData . container_id ) } ): ${ out } ` ) ;
927+ resolve ( false ) ;
928+ }
929+ } ;
930+
931+ // Add a guard timeout so we don't hang indefinitely
932+ const timer = setTimeout ( ( ) => {
933+ console . warn ( `cleanupOrphanedScripts: timeout while checking ${ String ( scriptData . script_name ) } on server ${ String ( ( server as any ) . name ) } ` ) ;
934+ finish ( ) ;
935+ } , 15000 ) ;
936+
913937 void sshExecutionService . executeCommand (
914-
915938 server as Server ,
916939 checkCommand ,
917940 ( data : string ) => {
918- resolve ( data . trim ( ) === 'exists' ) ;
941+ combinedOutput += data ;
919942 } ,
920943 ( error : string ) => {
921- console . error ( `Error checking container ${ scriptData . script_name } :` , error ) ;
922- resolve ( false ) ;
944+ combinedOutput += error ;
923945 } ,
924946 ( _exitCode : number ) => {
925- resolve ( false ) ;
947+ clearTimeout ( timer ) ;
948+ finish ( ) ;
926949 }
927950 ) ;
928951 } ) ;
You can’t perform that action at this time.
0 commit comments