8000 wait for procdump to exit too. (#7731) · HighAvailabilityLab/arangodb@7acb3b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7acb3b3

Browse files
dothebartmchacki
authored andcommitted
wait for procdump to exit too. (arangodb#7731)
* wait for procdump to exit too. * move running process check up, propagate status. First check whether processes are still running before attempting to force kill them * only list processes, don't change their state * add stopping procdump in all places
1 parent a19f90c commit 7acb3b3

File tree

6 files changed

+71
-38
lines changed

6 files changed

+71
-38
lines changed

UnitTests/unittest.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ function main (argv) {
268268
crashed: true
269269
});
270270

271+
let running = require("internal").getExternalSpawned();
272+
let i = 0;
273+
for (i = 0; i < running.length; i++) {
274+
let status = require("internal").statusExternal(running[i].pid, false);
275+
if (status.status === "TERMINATED") {
276+
print("process exited without us joining it (marking crashy): " + JSON.stringify(running[i]) + JSON.stringify(status));
277+
}
278+
else {
279+
print("Killing remaining process & marking crashy: " + JSON.stringify(running[i]));
280+
print(require("internal").killExternal(running[i].pid, abortSignal));
281+
}
282+
res.crashed = true;
283+
};
284+
271285
// whether or not there was an error
272286
try {
273287
fs.write(testOutputDirectory + '/UNITTEST_RESULT_EXECUTIVE_SUMMARY.json', String(res.status), true);
@@ -313,12 +327,6 @@ function main (argv) {
313327
// creates yaml like dump at the end
314328
UnitTest.unitTestPrettyPrintResults(res, testOutputDirectory, options);
315329

316-
let running = require("internal").getExternalSpawned();
317-
let i = 0;
318-
for (i = 0; i < running.length; i++) {
319-
print("Killing remaining process: " + JSON.stringify(running[i]));
320-
print(require("internal").killExternal(running[i].pid, abortSignal));
321-
};
322330
return res.status && running.length === 0;
323331
}
324332

js/client/modules/@arangodb/crash-utils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ function analyzeCrash (binary, instanceInfo, options, checkStr) {
278278
instanceInfo.exitStatus['gdbHint'] = "coredump unavailable";
279279
return;
280280
}
281-
if (instanceInfo.monitor.pid !== null) {
282-
instanceInfo.monitor = statusExternal(instanceInfo.monitor.pid, true);
283-
}
281+
pu.stopProcdump(options, instanceInfo);
284282
hint = analyzeCoreDumpWindows(instanceInfo);
285283
} else if (platform === 'darwin') {
286284
// fs.copyFile(binary, storeArangodPath);

js/client/modules/@arangodb/process-utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ function runProcdump (options, instanceInfo, rootDir, pid) {
498498
}
499499
}
500500

501+
function stopProcdump (options, instanceInfo) {
502+
if (instanceInfo.hasOwnProperty('monitor') &&
503+
instanceInfo.monitor.pid !== null) {
504+
print("wating for procdump to exit");
505+
statusExternal(instanceInfo.monitor.pid, true);
506+
instanceInfo.monitor.pid = null;
507+
}
508+
}
501509
// //////////////////////////////////////////////////////////////////////////////
502510
// / @brief executes a command and waits for result
503511
// //////////////////////////////////////////////////////////////////////////////
@@ -562,6 +570,7 @@ function executeAndWait (cmd, args, options, valgrindTest, rootDir, circumventCo
562570
runProcdump(options, instanceInfo, rootDir, res.pid);
563571
Object.assign(instanceInfo.exitStatus,
564572
statusExternal(res.pid, true));
573+
stopProcdump(options, instanceInfo);
565574
} else {
566575
res = executeExternalAndWait(cmd, args);
567576
instanceInfo.pid = res.pid;
@@ -1105,11 +1114,13 @@ function shutdownInstance (instanceInfo, options, forceTerminate) {
11051114
print("shutdownInstance: Marking crashy - " + JSON.stringify(arangod));
11061115
serverCrashedLocal = true;
11071116
}
1117+
stopProcdump(options, arangod);
11081118
} else {
11091119
if (arangod.role !== 'agent') {
11101120
nonAgenciesCount --;
11111121
}
11121122
print('Server "' + arangod.role + '" shutdown: Success: pid', arangod.pid);
1123+
stopProcdump(options, arangod);
11131124
return false;
11141125
}
11151126
});
@@ -1570,6 +1581,7 @@ exports.findFreePort = findFreePort;
15701581

15711582
exports.executeArangod = executeArangod;
15721583
exports.executeAndWait = executeAndWait;
1584+
exports.stopProcdump = stopProcdump;
15731585

15741586
exports.createBaseConfig = createBaseConfigBuilder;
15751587
exports.run = {

lib/Basics/process-utils.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,8 @@ ExternalId::ExternalId():
9898
ExternalProcess::ExternalProcess():
9999
_numberArguments(0),
100100
_arguments(nullptr),
101-
#ifndef _WIN32
102-
_pid(0),
103-
_readPipe(-1),
104-
_writePipe(-1),
105-
#else
106-
_pid(0),
101+
#ifdef _WIN32
107102
_process(nullptr),
108-
_readPipe(INVALID_HANDLE_VALUE),
109-
_writePipe(INVALID_HANDLE_VALUE),
110103
#endif
111104
_status(TRI_EXT_NOT_STARTED),
112105
_exitStatus(0) {}
@@ -1087,7 +1080,7 @@ ExternalProcessStatus TRI_CheckExternalProcess(ExternalId pid,
10871080
wantGetExitCode = true;
10881081
break;
10891082
case WAIT_TIMEOUT:
1090-
// success - everything went well.
1083+
// success - process is up and running.
10911084
external->_exitStatus = 0;
10921085
break;
10931086
case WAIT_FAILED:
@@ -1117,6 +1110,8 @@ ExternalProcessStatus TRI_CheckExternalProcess(ExternalId pid,
11171110
std::string("exit status could not be determined for pid ") +
11181111
arangodb::basics::StringUtils::itoa(
11191112
static_cast<int64_t>(external->_pid));
1113+
external->_exitStatus = -1;
1114+
external->_status = TRI_EXT_NOT_STARTED;
11201115
} else {
11211116
if (exitCode == STILL_ACTIVE) {
11221117
external->_exitStatus = 0;

lib/Basics/process-utils.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,13 @@ struct ExternalId {
100100
/// @brief external process description
101101
////////////////////////////////////////////////////////////////////////////////
102102

103-
struct ExternalProcess {
103+
struct ExternalProcess : public ExternalId {
104104
std::string _executable;
105105
size_t _numberArguments;
106106
char** _arguments;
107107

108-
#ifndef _WIN32
109-
TRI_pid_t _pid;
110-
int _readPipe;
111-
int _writePipe;
112-
#else
113-
DWORD _pid;
108+
#ifdef _WIN32
114109
HANDLE _process;
115-
HANDLE _readPipe;
116-
HANDLE _writePipe;
117110
#endif
118111

119112
TRI_external_status_e _status;

lib/V8/v8-utils.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,10 +3522,10 @@ static void JS_HMAC(v8::FunctionCallbackInfo<v8::Value> const& args) {
35223522
////////////////////////////////////////////////////////////////////////////////
35233523
/// @brief Convert programm stati to V8
35243524
////////////////////////////////////////////////////////////////////////////////
3525-
static char const* convertProcessStatusToString(ExternalProcessStatus external) {
3525+
static char const* convertProcessStatusToString(TRI_external_status_e processStatus) {
35263526
char const* status = "UNKNOWN";
35273527

3528-
switch (external._status) {
3528+
switch (processStatus) {
35293529
case TRI_EXT_NOT_STARTED:
35303530
status = "NOT-STARTED";
35313531
break;
@@ -3556,7 +3556,7 @@ static char const* convertProcessStatusToString(ExternalProcessStatus external)
35563556

35573557
static void convertPipeStatus(v8::FunctionCallbackInfo<v8::Value> const& args,
35583558
v8::Handle<v8::Object> &result,
3559-
ExternalId &external) {
3559+
ExternalId const& external) {
35603560
TRI_V8_TRY_CATCH_BEGIN(isolate);
35613561

35623562
result->Set(TRI_V8_ASCII_STRING(isolate, "pid"),
@@ -3593,14 +3593,14 @@ static void convertPipeStatus(v8::FunctionCallbackInfo<v8::Value> const& args,
35933593

35943594
static void convertStatusToV8(v8::FunctionCallbackInfo<v8::Value> const& args,
35953595
v8::Handle<v8::Object> &result,
3596-
ExternalProcessStatus &external_status,
3597-
ExternalId &external) {
3596+
ExternalProcessStatus const& external_status,
3597+
ExternalId const& external) {
35983598
TRI_V8_TRY_CATCH_BEGIN(isolate);
35993599

36003600
convertPipeStatus(args, result, external);
36013601

36023602
result->Set(TRI_V8_ASCII_STRING(isolate, "status"),
3603-
TRI_V8_ASCII_STRING(isolate, convertProcessStatusToString(external_status)));
3603+
TRI_V8_ASCII_STRING(isolate, convertProcessStatusToString(external_status._status)));
36043604

36053605
if (external_status._status == TRI_EXT_TERMINATED) {
36063606
result->Set(TRI_V8_ASCII_STRING(isolate, "exit"),
@@ -3618,6 +3618,36 @@ static void convertStatusToV8(v8::FunctionCallbackInfo<v8::Value> const& args,
36183618
TRI_V8_TRY_CATCH_END;
36193619
}
36203620

3621+
static void convertProcessInfoToV8(v8::FunctionCallbackInfo<v8::Value> const& args,
3622+
v8::Handle<v8::Object> &result,
3623+
ExternalProcess const& external_process) {
3624+
TRI_V8_TRY_CATCH_BEGIN(isolate);
3625+
3626+
convertPipeStatus(args, result, external_process);
3627+
3628+
result->Set(TRI_V8_ASCII_STRING(isolate, "status"),
3629+
TRI_V8_ASCII_STRING(isolate, convertProcessStatusToString(external_process._status)));
3630+
3631+
if (external_process._status == TRI_EXT_TERMINATED) {
3632+
result->Set(TRI_V8_ASCII_STRING(isolate, "exit"),
3633+
v8::Integer::New(isolate, static_cast<int32_t>(
3634+
external_process._exitStatus)));
3635+
} else if (external_process._status == TRI_EXT_ABORTED) {
3636+
result->Set(TRI_V8_ASCII_STRING(isolate, "signal"),
3637+
v8::Integer::New(isolate, static_cast<int32_t>(
3638+
external_process._exitStatus)));
3639+
}
3640+
result->Set(TRI_V8_ASCII_STRING(isolate, "executable"),
3641+
TRI_V8_STD_STRING(isolate, external_process._executable));
3642+
3643+
v8::Handle<v8::Array> arguments =
3644+
v8::Array::New(isolate, static_cast<int>(external_process._numberArguments));
3645+
for (size_t i = 0; i < external_process._numberArguments; i++) {
3646+
arguments->Set(i, TRI_V8_ASCII_STRING(isolate, external_process._arguments[i]));
3647+
}
3648+
result->Set(TRI_V8_ASCII_STRING(isolate, "arguments"), arguments);
3649+
TRI_V8_TRY_CATCH_END;
3650+
}
36213651
////////////////////////////////////////////////////////////////////////////////
36223652
/// @brief lists all running external processes
36233653
////////////////////////////////////////////////////////////////////////////////
@@ -3638,10 +3668,7 @@ static void JS_GetExternalSpawned(
36383668
uint32_t i = 0;
36393669
for (auto const& process : ExternalProcesses) {
36403670
v8::Handle<v8::Object> oneProcess = v8::Object::New(isolate);
3641-
ExternalId external;
3642-
external._pid = process->_pid;
3643-
auto external_status = TRI_CheckExternalProcess(external, false);
3644-
convertStatusToV8(args, oneProcess, external_status, external);
3671+
convertProcessInfoToV8(args, oneProcess, *process);
36453672
spawnedProcesses->Set(i, oneProcess);
36463673
i++;
36473674
}
@@ -3750,7 +3777,7 @@ static void JS_StatusExternal(v8::FunctionCallbackInfo<v8::Value> const& args) {
37503777
v8::Handle<v8::Object> result = v8::Object::New(isolate);
37513778

37523779
result->Set(TRI_V8_ASCII_STRING(isolate, "status"),
3753-
TRI_V8_STRING(isolate, convertProcessStatusToString(external)));
3780+
TRI_V8_STRING(isolate, convertProcessStatusToString(external._status)));
37543781

37553782
if (external._status == TRI_EXT_TERMINATED) {
37563783
result->Set(

0 commit comments

Comments
 (0)
0