Merge pull request 'bugfix/hanging-background-processes' (#54) from bugfix/hanging-background-processes into master
Reviewed-on: https://192.168.8.63/git/darthrubik/drharness/pulls/54
This commit was merged in pull request #54.
This commit is contained in:
@@ -41,6 +41,15 @@ timeout 5s "${DRHARNESS}" -F chat3.json -n -m "This is a test" -t run_dangerous_
|
||||
|
||||
echo "PASS: tool_shell"
|
||||
|
||||
tool_call run_dangerous_shell '{"command":"printf \"test\"; sleep 10 &","timeout_seconds":1}' >> background_task_test.txt
|
||||
be_done 'done' >> background_task_test.txt
|
||||
|
||||
# If we hit the timeout of the timeout utility then we fail
|
||||
timeout 5s "${DRHARNESS}" -F background_task_test.json -n -m "This is a test" -t run_dangerous_shell -d < "background_task_test.txt"
|
||||
|
||||
echo "PASS: background_task_test"
|
||||
|
||||
|
||||
|
||||
seq 1 1044 > long_file
|
||||
tool_call run_dangerous_shell '{"command":"cat long_file"}' >> mock_responses4.txt
|
||||
|
||||
+11
-10
@@ -128,19 +128,20 @@ Tool make_shell_tool(bool safe) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 3. Read data if available - keep reading until no more data
|
||||
// 3. Read data if available - read once, don't block waiting for more
|
||||
// If POLLHUP is not set, a background process may keep the pipe open,
|
||||
// so we can't read in a loop (would block waiting for more data).
|
||||
if (pfd.revents & POLLIN) {
|
||||
while (true) {
|
||||
res = read(pfd.fd, buf.data(), buf.size());
|
||||
if (res < 0) {
|
||||
if (errno == EINTR) continue; // Restart if interrupted by signal
|
||||
break; // Error
|
||||
} else if (res == 0) { // EOF
|
||||
break;
|
||||
}
|
||||
res = read(pfd.fd, buf.data(), buf.size());
|
||||
if (res > 0) {
|
||||
output += std::string(buf.data(), res);
|
||||
}
|
||||
break;
|
||||
// If POLLHUP is also set, we're done
|
||||
if (pfd.revents & POLLHUP) {
|
||||
break;
|
||||
}
|
||||
// Otherwise, continue polling for more data or timeout
|
||||
// Don't break here - continue the loop
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user