From 4bab06dfff33d31b0fce1e2eebf78f6fc1383caa Mon Sep 17 00:00:00 2001 From: Adrian Muzyka Date: Wed, 15 May 2024 14:10:12 +0200 Subject: [PATCH 1/4] Improve recovery on Hibernate error and cleanup --- daemon/lib/source/DobbyHibernate.cpp | 13 ++++++++---- daemon/lib/source/DobbyHibernate.h | 3 ++- daemon/lib/source/DobbyManager.cpp | 31 ++-------------------------- 3 files changed, 13 insertions(+), 34 deletions(-) diff --git a/daemon/lib/source/DobbyHibernate.cpp b/daemon/lib/source/DobbyHibernate.cpp index 4508be3b..6ac62214 100644 --- a/daemon/lib/source/DobbyHibernate.cpp +++ b/daemon/lib/source/DobbyHibernate.cpp @@ -43,7 +43,8 @@ typedef enum { typedef enum { MEMCR_OK = 0, MEMCR_ERROR = -1, - MEMCR_INVALID_PID = -2 + MEMCR_INVALID_PID = -2, + MEMCR_SOCKET_READ_ERROR = -3 } ServerResponseCode; typedef struct { @@ -142,7 +143,6 @@ static bool SendRcvCmd(const ServerRequest* cmd, ServerResponse* resp, uint32_t AI_LOG_FN_ENTRY(); int cd; int ret; - struct sockaddr_in addr = { 0 }; resp->respCode = MEMCR_ERROR; cd = Connect(serverLocator, timeoutMs); @@ -154,7 +154,7 @@ static bool SendRcvCmd(const ServerRequest* cmd, ServerResponse* resp, uint32_t ret = write(cd, cmd, sizeof(ServerRequest)); if (ret != sizeof(ServerRequest)) { - AI_LOG_ERROR("Socket write failed: ret %d", ret); + AI_LOG_ERROR("Socket write failed: ret %d, %m", ret); close(cd); AI_LOG_FN_EXIT(); return false; @@ -162,7 +162,8 @@ static bool SendRcvCmd(const ServerRequest* cmd, ServerResponse* resp, uint32_t ret = read(cd, resp, sizeof(ServerResponse)); if (ret != sizeof(ServerResponse)) { - AI_LOG_ERROR("Socket read failed: ret %d", ret); + AI_LOG_ERROR("Socket read failed: ret %d, %m", ret); + resp->respCode = MEMCR_SOCKET_READ_ERROR; close(cd); AI_LOG_FN_EXIT(); return false; @@ -188,6 +189,10 @@ DobbyHibernate::Error DobbyHibernate::HibernateProcess(const pid_t pid, const ui AI_LOG_INFO("Hibernate process PID %d success", pid); AI_LOG_FN_EXIT(); return DobbyHibernate::Error::ErrorNone; + } else if (resp.respCode == MEMCR_SOCKET_READ_ERROR) { + AI_LOG_WARN("Error Hibernate timeout process PID %d ret %d", pid, resp.respCode); + AI_LOG_FN_EXIT(); + return DobbyHibernate::Error::ErrorTimeout; } else { AI_LOG_WARN("Error Hibernate process PID %d ret %d", pid, resp.respCode); AI_LOG_FN_EXIT(); diff --git a/daemon/lib/source/DobbyHibernate.h b/daemon/lib/source/DobbyHibernate.h index d060330b..8045173c 100644 --- a/daemon/lib/source/DobbyHibernate.h +++ b/daemon/lib/source/DobbyHibernate.h @@ -32,7 +32,8 @@ class DobbyHibernate enum Error { ErrorNone = 0, - ErrorGeneral = 1 + ErrorGeneral = 1, + ErrorTimeout = 2 }; enum CompressionAlg diff --git a/daemon/lib/source/DobbyManager.cpp b/daemon/lib/source/DobbyManager.cpp index 93d74a1e..272423f8 100644 --- a/daemon/lib/source/DobbyManager.cpp +++ b/daemon/lib/source/DobbyManager.cpp @@ -1566,35 +1566,7 @@ bool DobbyManager::hibernateContainer(int32_t cd, const std::string& options) std::thread hibernateThread = std::thread([=]() { - //TODO: --delay support is temporary and should be removed - int delayMs = 0; - size_t delayMsPos = options.find("--delay="); - if (delayMsPos != std::string::npos) - { - delayMs = std::stoi(&options[delayMsPos + std::string("--delay=").length()], nullptr, 10); - } DobbyHibernate::Error ret = DobbyHibernate::Error::ErrorNone; - - int delayChunkMs = 100; - while (delayMs > 0) - { - int sleepTime = delayMs > delayChunkMs? delayChunkMs : delayMs; - delayMs -= sleepTime; - std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); - { - std::lock_guard locker(mLock); - if (mContainers.find(id) == mContainers.end() || - mContainers[id]->descriptor != cd || - mContainers[id]->state != DobbyContainer::State::Hibernating) - { - AI_LOG_WARN("Hibernation of: %s with descriptor %d aborted", id.c_str(), cd); - AI_LOG_FN_EXIT(); - return; - } - } - } - //TODO: --delay support end - // create a stats object for the container to get list of PIDs std::unique_lock locker(mLock); DobbyStats stats(it->first, mEnvironment, mUtilities); @@ -1619,7 +1591,8 @@ bool DobbyManager::hibernateContainer(int32_t cd, const std::string& options) if (ret != DobbyHibernate::Error::ErrorNone) { AI_LOG_WARN("Error hibernating pid: '%d'", pid); - // revert previous Hibernations and break + // try to revert current and previous Hibernations and break + DobbyHibernate::WakeupProcess(pid); while (pidIt != jsonPids.begin()) { --pidIt; From 60492af3f95eed8fc0f808674bd0142deff7c8ee Mon Sep 17 00:00:00 2001 From: Karthick Swaminathan <85346280+ks734@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:56:27 +0530 Subject: [PATCH 2/4] Update CMakeLists.txt --- daemon/process/CMakeLists.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/daemon/process/CMakeLists.txt b/daemon/process/CMakeLists.txt index 6e4b30d4..afb08f56 100644 --- a/daemon/process/CMakeLists.txt +++ b/daemon/process/CMakeLists.txt @@ -128,11 +128,14 @@ endif() message("Using settings from ${DOBBY_SETTINGS_FILE}") -install( - FILES "${DOBBY_SETTINGS_FILE}" - RENAME dobby.json - DESTINATION /etc/ ) - +if ( "${DOBBY_SETTINGS_FILE}" STREQUAL "DONT_INSTALL_DEVICESETTINGSFILE" ) + message("Skipping the installation of device settings file") +else() + install( + FILES "${DOBBY_SETTINGS_FILE}" + RENAME dobby.json + DESTINATION /etc/ ) +endif() if (USE_SYSTEMD) # Install a systemd launch service config and enables it by default From 2e143b609c20ee92399c9768c03b7d418c506a9c Mon Sep 17 00:00:00 2001 From: Karthick Swaminathan <85346280+ks734@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:06:28 +0530 Subject: [PATCH 3/4] Update CMakeLists.txt --- daemon/process/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/daemon/process/CMakeLists.txt b/daemon/process/CMakeLists.txt index afb08f56..e53de145 100644 --- a/daemon/process/CMakeLists.txt +++ b/daemon/process/CMakeLists.txt @@ -126,11 +126,10 @@ else() endif() endif() -message("Using settings from ${DOBBY_SETTINGS_FILE}") - if ( "${DOBBY_SETTINGS_FILE}" STREQUAL "DONT_INSTALL_DEVICESETTINGSFILE" ) message("Skipping the installation of device settings file") else() + message("Using settings from ${DOBBY_SETTINGS_FILE}") install( FILES "${DOBBY_SETTINGS_FILE}" RENAME dobby.json From d1841fbc429c9950f7e3af392e41ff39ad891a5b Mon Sep 17 00:00:00 2001 From: Karthick Swaminathan <85346280+ks734@users.noreply.github.com> Date: Wed, 28 Aug 2024 19:19:40 +0530 Subject: [PATCH 4/4] Update v3.10.2 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a4ce50c..9e0e2b22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,13 +22,13 @@ cmake_minimum_required( VERSION 3.7.0 ) include(GNUInstallDirs) # Project setup -project( Dobby VERSION "3.10.1" ) +project( Dobby VERSION "3.10.2" ) # Set the major and minor version numbers of dobby (also used by plugins) set( DOBBY_MAJOR_VERSION 3 ) set( DOBBY_MINOR_VERSION 10 ) -set( DOBBY_MICRO_VERSION 1 ) +set( DOBBY_MICRO_VERSION 2 ) set(INSTALL_CMAKE_DIR lib/cmake/Dobby)