Skip to content

Commit 6e24f75

Browse files
committed
[lldb] Improved lldb-server stability for remote launching
We faced the issue running cross api tests in 8 threads. The executable is installed to the target by the process `lldb-server platform`, but launched by the another process `lldb-server gdbserver`. We got the error ETXTBSY on Linux and ERROR_SHARING_VIOLATION on Windows. It seems the known issue and ProcessLauncherPosixFork.cpp already contains the workaround, but it is not enough. Updated the workaround with the total timeout 5 seconds and added the same workaround to ProcessLauncherWindows.cpp too.
1 parent b1f263e commit 6e24f75

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lldb/source/Host/posix/ProcessLauncherPosixFork.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ struct ForkLaunchInfo {
201201
execve(info.argv[0], const_cast<char *const *>(info.argv), info.envp);
202202

203203
#if defined(__linux__)
204-
if (errno == ETXTBSY) {
204+
for (int i = 0; i < 50; ++i) {
205205
// On android M and earlier we can get this error because the adb daemon
206206
// can hold a write handle on the executable even after it has finished
207207
// uploading it. This state lasts only a short time and happens only when
@@ -210,7 +210,9 @@ struct ForkLaunchInfo {
210210
// shell" command in the fork() child before it has had a chance to exec.)
211211
// Since this state should clear up quickly, wait a while and then give it
212212
// one more go.
213-
usleep(50000);
213+
if (errno != ETXTBSY)
214+
break;
215+
usleep(100000);
214216
execve(info.argv[0], const_cast<char *const *>(info.argv), info.envp);
215217
}
216218
#endif

lldb/source/Host/windows/ProcessLauncherWindows.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,30 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
113113
// command line is not empty, its contents may be modified by CreateProcessW.
114114
WCHAR *pwcommandLine = wcommandLine.empty() ? nullptr : &wcommandLine[0];
115115

116-
BOOL result = ::CreateProcessW(
116+
BOOL result;
117+
DWORD last_error = 0;
118+
// This is the workaround for the error "The process cannot access the file
119+
// because it is being used by another process". Note the executable file is
120+
// installed to the target by the process `lldb-server platform`, but launched
121+
// by the process `lldb-server gdbserver`. Sometimes system may block the file
122+
// for some time after copying.
123+
for (int i = 0; i < 50; ++i) {
124+
result = ::CreateProcessW(
117125
wexecutable.c_str(), pwcommandLine, NULL, NULL, TRUE, flags, env_block,
118126
wworkingDirectory.size() == 0 ? NULL : wworkingDirectory.c_str(),
119127
&startupinfo, &pi);
128+
if (!result) {
129+
last_error = ::GetLastError();
130+
if (last_error != ERROR_SHARING_VIOLATION)
131+
break;
132+
::Sleep(100);
133+
} else
134+
break;
135+
}
120136

121137
if (!result) {
122138
// Call GetLastError before we make any other system calls.
123-
error.SetError(::GetLastError(), eErrorTypeWin32);
139+
error.SetError(last_error, eErrorTypeWin32);
124140
// Note that error 50 ("The request is not supported") will occur if you
125141
// try debug a 64-bit inferior from a 32-bit LLDB.
126142
}

0 commit comments

Comments
 (0)