From 6206f91d56fc84c2c6e40dac3c2e0205b644accc Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Fri, 7 Mar 2014 16:20:12 +0100 Subject: [PATCH 1/3] Yet another fix for process shutdown on Unix. --- .../modules/org/arangodb/cluster/kickstarter.js | 16 ++++++++-------- lib/BasicsC/process-utils.c | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/js/server/modules/org/arangodb/cluster/kickstarter.js b/js/server/modules/org/arangodb/cluster/kickstarter.js index 55193c45d7..a6ba20fe73 100644 --- a/js/server/modules/org/arangodb/cluster/kickstarter.js +++ b/js/server/modules/org/arangodb/cluster/kickstarter.js @@ -356,13 +356,10 @@ launchActions.createSystemColls = function (dispatchers, cmd, isRelaunch) { shutdownActions.startAgent = function (dispatchers, cmd, run) { console.info("Shutting down agent %s", JSON.stringify(run.pid)); killExternal(run.pid); - statusExternal(run.pid); return {"error": false, "isStartAgent": true}; }; shutdownActions.sendConfiguration = function (dispatchers, cmd, run) { - console.info("Waiting for 3 seconds for servers before shutting down agency."); - wait(3); return {"error": false, "isSendConfiguration": true}; }; @@ -379,12 +376,15 @@ shutdownActions.startServers = function (dispatchers, cmd, run) { } download(url,"",{method:"GET", headers: hdrs}); } - console.info("Waiting 3 seconds for servers to shutdown gracefully..."); - wait(3); + console.info("Waiting 5 seconds for servers to shutdown gracefully..."); + wait(5); for (i = 0;i < run.pids.length;i++) { - console.info("Shutting down %s the hard way...", JSON.stringify(run.pids[i])); - killExternal(run.pids[i]); - statusExternal(run.pids[i]); + var s = statusExternal(run.pids[i]); + if (s.status !== "TERMINATED") { + console.info("Shutting down %s the hard way...", + JSON.stringify(run.pids[i])); + killExternal(run.pids[i]); + } } return {"error": false, "isStartServers": true}; }; diff --git a/lib/BasicsC/process-utils.c b/lib/BasicsC/process-utils.c index 531d5d7913..e5c453a180 100644 --- a/lib/BasicsC/process-utils.c +++ b/lib/BasicsC/process-utils.c @@ -970,7 +970,12 @@ TRI_external_status_t TRI_CheckExternalProcess (TRI_external_id_t pid, #ifndef _WIN32 static bool ourKillProcess(TRI_external_t* pid) { - return (0 != kill(pid->_pid, SIGTERM)); + bool success; + int loc; + success = (0 != kill(pid->_pid, SIGTERM)); + // And wait for it to avoid a zombie: + waitpid(pid->_pid, &loc, WUNTRACED); + return success; } #else static bool ourKillProcess(TRI_external_t* pid) { @@ -1019,6 +1024,8 @@ bool TRI_KillExternalProcess (TRI_external_id_t pid) { TRI_external_t* external; size_t i; bool ok = true; + bool success; + int loc; TRI_LockMutex(&ExternalProcessesLock); @@ -1034,7 +1041,10 @@ bool TRI_KillExternalProcess (TRI_external_id_t pid) { TRI_UnlockMutex(&ExternalProcessesLock); #ifndef _WIN32 // Kill just in case: - return (0 != kill(pid._pid, SIGTERM)); + success = (0 != kill(pid._pid, SIGTERM)); + // And wait for it to avoid a zombie: + waitpid(pid._pid, &loc, WUNTRACED); + return success; #else return ourKillProcessPID(pid._pid); #endif From 41341f3023adabd495afd750629d7f2ac238d240 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 7 Mar 2014 16:30:04 +0100 Subject: [PATCH 2/3] fixed jslint warnings --- js/apps/system/aardvark/frontend/js/views/databaseView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/apps/system/aardvark/frontend/js/views/databaseView.js b/js/apps/system/aardvark/frontend/js/views/databaseView.js index 9a4c362100..43aa6e9326 100644 --- a/js/apps/system/aardvark/frontend/js/views/databaseView.js +++ b/js/apps/system/aardvark/frontend/js/views/databaseView.js @@ -134,7 +134,7 @@ deleteDatabase: function(e) { this.hideModal('editDatabaseModal'); this.dbToDelete = $('#editDatabaseName').html(); - this.showModal('deleteDatabaseModal') + this.showModal('deleteDatabaseModal'); }, currentDatabase: function() { @@ -162,7 +162,7 @@ $('#editDatabaseName').html(dbName); var button = $('#deleteDatabase'); if(dbName === this.currentDB) { - var element + var element; button.prop('disabled', true); button.removeClass('button-danger'); button.addClass('button-neutral'); From cd0a33de9f4f612ab1fb160e41dc92b36897dc7d Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Fri, 7 Mar 2014 16:48:21 +0100 Subject: [PATCH 3/3] Seemingly fix behaviour on Windows. Note: WSACleanup complains and we do not know a fix. --- arangod/RestServer/arango.cpp | 8 +++--- lib/BasicsC/socket-utils.c | 47 +++++++++++++++++------------------ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/arangod/RestServer/arango.cpp b/arangod/RestServer/arango.cpp index e0452b9a59..c09ea40c7a 100644 --- a/arangod/RestServer/arango.cpp +++ b/arangod/RestServer/arango.cpp @@ -454,15 +454,15 @@ int main (int argc, char* argv[]) { #endif - // shutdown sub-systems - TRIAGENS_REST_SHUTDOWN; - TRI_GlobalExitFunction(res, NULL); - if (ArangoInstance != 0) { delete ArangoInstance; ArangoInstance = 0; } + // shutdown sub-systems + TRIAGENS_REST_SHUTDOWN; + TRI_GlobalExitFunction(res, NULL); + return res; } diff --git a/lib/BasicsC/socket-utils.c b/lib/BasicsC/socket-utils.c index bd64de10a6..5642b2835c 100644 --- a/lib/BasicsC/socket-utils.c +++ b/lib/BasicsC/socket-utils.c @@ -52,6 +52,27 @@ int TRI_closesocket (TRI_socket_t s) { int res = 0; #ifdef _WIN32 + if (s.fileHandle != TRI_INVALID_SOCKET) { + res = shutdown(s.fileHandle, SD_SEND); + + if (res != 0) { + // Windows complains about shutting down a socket that was not bound + // so we will not print out the error here + // LOG_WARNING("socket shutdown error: %d", WSAGetLastError()); + } + else { + char buf[256]; + int len; + do { + len = TRI_readsocket(s, buf, sizeof(buf), 0); + } while (len > 0); + + } + res = closesocket(s.fileHandle); + + if (res != 0) { + LOG_WARNING("socket close error: %d", WSAGetLastError()); + } if (s.fileDescriptor != -1) { res = _close(s.fileDescriptor); /* @@ -60,30 +81,8 @@ int TRI_closesocket (TRI_socket_t s) { so it is not necessary to call the Win32 function CloseHandle on the original handle. */ } - else if (s.fileHandle != TRI_INVALID_SOCKET) { - res = shutdown(s.fileHandle, SD_SEND); - - if (res != 0) { - // Windows complains about shutting down a socket that was not bound - // so we will not print out the error here - // LOG_WARNING("socket shutdown error: %d", WSAGetLastError()); - } - else { - char buf[256]; - int len; - do { - len = TRI_readsocket(s, buf, sizeof(buf), 0); - } - while (len > 0); - - res = closesocket(s.fileHandle); - - if (res != 0) { - LOG_WARNING("socket close error: %d", WSAGetLastError()); - } - } - } - #else + } +#else if (s.fileDescriptor != TRI_INVALID_SOCKET) { res = close(s.fileDescriptor); }