Fix data race of shell command

This commit is contained in:
Amos Bird 2023-08-21 19:35:09 +08:00
parent ec7b22d218
commit bd9f526f93
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
2 changed files with 15 additions and 4 deletions

View File

@ -101,6 +101,12 @@ bool ShellCommand::tryWaitProcessWithTimeout(size_t timeout_in_seconds)
out.close();
err.close();
for (auto & [_, fd] : write_fds)
fd.close();
for (auto & [_, fd] : read_fds)
fd.close();
return waitForPid(pid, timeout_in_seconds);
}
@ -287,6 +293,12 @@ int ShellCommand::tryWait()
out.close();
err.close();
for (auto & [_, fd] : write_fds)
fd.close();
for (auto & [_, fd] : read_fds)
fd.close();
LOG_TRACE(getLogger(), "Will wait for shell command pid {}", pid);
int status = 0;

View File

@ -439,11 +439,7 @@ namespace
}
if (!executor->pull(chunk))
{
if (check_exit_code)
command->wait();
return {};
}
current_read_rows += chunk.getNumRows();
}
@ -466,6 +462,9 @@ namespace
if (thread.joinable())
thread.join();
if (check_exit_code && !process_pool)
command->wait();
rethrowExceptionDuringSendDataIfNeeded();
}