Fixed contract output fetcher thread join issue.

This commit is contained in:
ravinsp
2020-10-06 17:00:38 +05:30
parent 54d6bf5bf6
commit 31048f55b8
2 changed files with 9 additions and 4 deletions

View File

@@ -52,11 +52,16 @@ namespace sc
// Wait for child process (contract process) to complete execution.
const int presult = await_process_execution(ctx.contract_pid);
ctx.contract_pid = 0;
LOG_DEBUG << "Contract process ended." << (ctx.args.readonly ? " (rdonly)" : "");
// Wait for the output collection thread to gracefully stop.
ctx.output_fetcher_thread.join();
// There could be 2 reasons for the contract to end; the contract voluntary finished execution or
// it was killed due to Hot Pocket shutting down.
// Wait for the output collection thread to gracefully stop if this is voluntary contract termination.
// 'ctx.should_stop' indicates Hot Pocket is shutting down. If that's the case ouput collection thread
// is joined by the deinit logic.
if (!ctx.should_stop && ctx.output_fetcher_thread.joinable())
ctx.output_fetcher_thread.join();
if (presult != 0)
{

View File

@@ -239,7 +239,7 @@ namespace util
const int wait_options = wait ? 0 : WNOHANG;
if (waitpid(pid, NULL, wait_options) == -1)
{
LOG_ERROR << errno << ": waitpid after kill failed.";
LOG_ERROR << errno << ": waitpid after kill (pid:" << pid << ") failed.";
return -1;
}