Skip to content

Commit

Permalink
[lldb/Core] Avoid more Communication::Disconnect races
Browse files Browse the repository at this point in the history
Calling Disconnect while the read thread is running is racy because the
thread can also call Disconnect.  This is a follow-up to b424b0b, which
reorders other occurences of Disconnect/StopReadThread I can find, and also
adds an assertion to guard against new occurences being introduced.
  • Loading branch information
labath committed Apr 23, 2020
1 parent 89cb5d5 commit 9321255
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lldb/source/Core/Communication.cpp
Expand Up @@ -71,8 +71,8 @@ Communication::~Communication() {

void Communication::Clear() {
SetReadThreadBytesReceivedCallback(nullptr, nullptr);
Disconnect(nullptr);
StopReadThread(nullptr);
Disconnect(nullptr);
}

ConnectionStatus Communication::Connect(const char *url, Status *error_ptr) {
Expand All @@ -93,6 +93,8 @@ ConnectionStatus Communication::Disconnect(Status *error_ptr) {
LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
"{0} Communication::Disconnect ()", this);

assert((!m_read_thread_enabled || m_read_thread_did_exit) &&
"Disconnecting while the read thread is running is racy!");
lldb::ConnectionSP connection_sp(m_connection_sp);
if (connection_sp) {
ConnectionStatus status = connection_sp->Disconnect(error_ptr);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/Process.cpp
Expand Up @@ -3316,8 +3316,8 @@ Status Process::Destroy(bool force_kill) {
DidDestroy();
StopPrivateStateThread();
}
m_stdio_communication.Disconnect();
m_stdio_communication.StopReadThread();
m_stdio_communication.Disconnect();
m_stdin_forward = false;

if (m_process_input_reader) {
Expand Down

0 comments on commit 9321255

Please sign in to comment.