Fix bug with timeouts

This commit is contained in:
andreas.dinauer 2025-10-30 21:05:13 +01:00
parent ac3c75dbdf
commit 282a12111c

View File

@ -19,6 +19,7 @@ import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.TimeUnit;
@ApplicationScoped @ApplicationScoped
public class NodeService implements ResourceService<NodeStats> public class NodeService implements ResourceService<NodeStats>
@ -82,12 +83,17 @@ public class NodeService implements ResourceService<NodeStats>
text.add(line); text.add(line);
} }
} }
boolean hasEndedInTime = p.waitFor(10, TimeUnit.SECONDS);
p.destroy();
if (hasEndedInTime)
{
int exitCode = p.waitFor(); int exitCode = p.waitFor();
if(exitCode == 0) if(exitCode == 0)
{ {
LOG.info("Found {} nodes", text.size()); LOG.info("Found {} nodes", text.size());
return text; return text;
} }
}
throw new RuntimeException("Failed to retrieve top nodes."); throw new RuntimeException("Failed to retrieve top nodes.");
} }