Skip to content

Commit

Permalink
[llvm] Fix bug leading to zombie llvm-size processes.
Browse files Browse the repository at this point in the history
This corrects my use of the boost::process API whereby llvm-size child
processes could become detached from the parent environment service
and be left as zombies.

I found this issue will attempting to reproduce facebookresearch#572. I'm not sure if
this bug is relevant.
  • Loading branch information
ChrisCummins committed Mar 6, 2022
1 parent 3c19686 commit 6d5184a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions compiler_gym/envs/llvm/service/Cost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,21 @@ Status getTextSizeInBytes(llvm::Module& module, int64_t* value, const fs::path&
bp::child llvmSize(llvmSizeCmd, bp::std_in.close(), bp::std_out > llvmSizeStdoutFuture,
bp::std_err > bp::null, llvmSizeStdoutStream);

if (!util::wait_for(llvmSize, std::chrono::seconds(60))) {
llvmSizeStdoutStream.run_for(std::chrono::seconds(60));
if (llvmSizeStdoutStream.poll()) {
return Status(StatusCode::DEADLINE_EXCEEDED,
fmt::format("Failed to compute .text size cost within 60 seconds"));
}
llvmSize.wait();
llvmSizeOutput = llvmSizeStdoutFuture.get();

llvmSizeStdoutStream.run();
fs::remove(tmpFile);
if (llvmSize.exit_code()) {
return Status(StatusCode::INVALID_ARGUMENT, fmt::format("Failed to compute .text size cost. "
"Command returned exit code {}: {}",
llvmSize.exit_code(), llvmSizeCmd));
}

llvmSizeOutput = llvmSizeStdoutFuture.get();
} catch (bp::process_error& e) {
fs::remove(tmpFile);
return Status(StatusCode::INVALID_ARGUMENT,
Expand Down Expand Up @@ -154,6 +155,7 @@ Status getTextSizeInBytes(llvm::Module& module, int64_t* value, const fs::path&
return Status(StatusCode::INTERNAL,
fmt::format("Failed to parse .TEXT size: `{}`\n", llvmSizeOutput));
}

return Status::OK;
}

Expand Down

0 comments on commit 6d5184a

Please sign in to comment.