From 1a26eec26cdcfb39310819df27bef355e33be429 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Sun, 17 Sep 2023 18:43:08 -0700 Subject: [PATCH 01/24] Validate Max Priority for Mac failure --- lib/tpm/TransmissionPolicyManager.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index fdf4f5cfb..48af99689 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -331,10 +331,21 @@ namespace MAT_NS_BEGIN { } bool forceTimerRestart = false; - // Initiate upload right away + // Check if it's time to execute the specific Max or other priority events code block + auto currentTime = std::chrono::steady_clock::now(); + static auto maxPriorityLastExecutionTime = currentTime; + + auto max_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - maxPriorityLastExecutionTime).count(); + + /* This logic needs to be revised: one event in a dedicated HTTP post is wasteful! */ + // Initiate upload right away, but add a 2-second check to ensure some delay between consecutive initiate upload calls. if (event->record.latency > EventLatency_RealTime) { + if(max_priority_elapsed_seconds < 2){ + return; + } auto ctx = m_system.createEventsUploadContext(); ctx->requestedMinLatency = event->record.latency; + maxPriorityLastExecutionTime = currentTime; addUpload(ctx); initiateUpload(ctx); return; From 55c7b91203d4efe549b8cb8ff317504c4096f501 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Sun, 17 Sep 2023 20:51:06 -0700 Subject: [PATCH 02/24] Add 1st upload stopage fix --- lib/tpm/TransmissionPolicyManager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 48af99689..e2943e84f 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -334,6 +334,7 @@ namespace MAT_NS_BEGIN { // Check if it's time to execute the specific Max or other priority events code block auto currentTime = std::chrono::steady_clock::now(); static auto maxPriorityLastExecutionTime = currentTime; + static auto otherPriorityLastExecutionTime = currentTime; auto max_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - maxPriorityLastExecutionTime).count(); @@ -351,6 +352,16 @@ namespace MAT_NS_BEGIN { return; } + // Other priorities like: Normal, Realtime, etc. + auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); + + // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. + // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. + if (other_priority_elapsed_seconds > 40 && m_isUploadScheduled.exchange(false)){ + LOG_TRACE("Trigger upload on event arrival"); + otherPriorityLastExecutionTime = currentTime; + } + // Schedule async upload if not scheduled yet if (!m_isUploadScheduled || TransmitProfiles::isTimerUpdateRequired()) { From 0540044fdba531856f6307e4f5a6a0f460f6a3a7 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Sun, 17 Sep 2023 22:54:09 -0700 Subject: [PATCH 03/24] Update 1 upload --- lib/tpm/TransmissionPolicyManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index e2943e84f..bb254dff5 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -357,7 +357,7 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. - if (other_priority_elapsed_seconds > 40 && m_isUploadScheduled.exchange(false)){ + if (other_priority_elapsed_seconds > 5 && m_isUploadScheduled.exchange(false)){ LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } From 1af6f6ec552fa7f030c2a4dc7c7bcedc258be5d4 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Sun, 17 Sep 2023 23:00:54 -0700 Subject: [PATCH 04/24] Update 1 upload --- lib/tpm/TransmissionPolicyManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index bb254dff5..410e92dc4 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -357,7 +357,7 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. - if (other_priority_elapsed_seconds > 5 && m_isUploadScheduled.exchange(false)){ + if (other_priority_elapsed_seconds > 1){ LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } From a0d8d5a509e649c473d20a878a53b2a7aee2790f Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Sun, 17 Sep 2023 23:03:54 -0700 Subject: [PATCH 05/24] Update 1 upload 2nd fix --- lib/tpm/TransmissionPolicyManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 410e92dc4..d6a3dd699 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -357,7 +357,7 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. - if (other_priority_elapsed_seconds > 1){ + if (other_priority_elapsed_seconds > 3 && m_isUploadScheduled.exchange(false)){ LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } From d1b9d8c32e4c9788a357683a54394c364ce14ce3 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Sun, 17 Sep 2023 23:26:41 -0700 Subject: [PATCH 06/24] Update 1 upload --- lib/tpm/TransmissionPolicyManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index d6a3dd699..b9bb0949b 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -357,7 +357,7 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. - if (other_priority_elapsed_seconds > 3 && m_isUploadScheduled.exchange(false)){ + if (other_priority_elapsed_seconds > 4 && m_isUploadScheduled.exchange(false)){ LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } @@ -365,6 +365,7 @@ namespace MAT_NS_BEGIN { // Schedule async upload if not scheduled yet if (!m_isUploadScheduled || TransmitProfiles::isTimerUpdateRequired()) { + otherPriorityLastExecutionTime = currentTime; if (updateTimersIfNecessary()) { m_timerdelay = std::chrono::milliseconds { m_timers[1] }; From 8de0ba264549f9a2e96253eb4daa82ef3d204afe Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Sun, 17 Sep 2023 23:28:51 -0700 Subject: [PATCH 07/24] Update 1 upload --- lib/tpm/TransmissionPolicyManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index b9bb0949b..f55ec9e9a 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -357,7 +357,7 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. - if (other_priority_elapsed_seconds > 4 && m_isUploadScheduled.exchange(false)){ + if (other_priority_elapsed_seconds > 4){ LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } From 0572f5603755c3f23457753d4f522ea2aac30485 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Mon, 18 Sep 2023 02:11:19 -0700 Subject: [PATCH 08/24] Fix --- lib/tpm/TransmissionPolicyManager.cpp | 19 ++++++++++++++++--- lib/tpm/TransmissionPolicyManager.hpp | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index f55ec9e9a..95771a85e 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -52,6 +52,7 @@ namespace MAT_NS_BEGIN { m_backoff = IBackoff::createFromConfig(m_backoffConfig); assert(m_backoff); m_deviceStateHandler.Start(); + otherPriorityLastExecutionTime = std::chrono::steady_clock::now(); } TransmissionPolicyManager::~TransmissionPolicyManager() @@ -334,7 +335,6 @@ namespace MAT_NS_BEGIN { // Check if it's time to execute the specific Max or other priority events code block auto currentTime = std::chrono::steady_clock::now(); static auto maxPriorityLastExecutionTime = currentTime; - static auto otherPriorityLastExecutionTime = currentTime; auto max_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - maxPriorityLastExecutionTime).count(); @@ -357,7 +357,8 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. - if (other_priority_elapsed_seconds > 4){ + if (other_priority_elapsed_seconds > 40 && m_isUploadScheduled.load()){ + m_isUploadScheduled.exchange(false); LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } @@ -479,12 +480,24 @@ namespace MAT_NS_BEGIN { { bool result = m_scheduledUpload.Cancel(getCancelWaitTime().count()); + // Check if it's time to execute the specific code block + auto currentTime = std::chrono::steady_clock::now(); + + auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); + // TODO: There is a potential for upload tasks to not be canceled, especially if they aren't waited for. // We either need a stronger guarantee here (could impact SDK performance), or a mechanism to // ensure those tasks are canceled when the log manager is destroyed. Issue 388 - if (result) + // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. + // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. + if (result || other_priority_elapsed_seconds > 40) { m_isUploadScheduled.exchange(false); + if (other_priority_elapsed_seconds > 40) + { + LOG_TRACE("Reset upload on event cancellation"); + } + otherPriorityLastExecutionTime = currentTime; } return result; } diff --git a/lib/tpm/TransmissionPolicyManager.hpp b/lib/tpm/TransmissionPolicyManager.hpp index eb2bd4b34..7bf6a7549 100644 --- a/lib/tpm/TransmissionPolicyManager.hpp +++ b/lib/tpm/TransmissionPolicyManager.hpp @@ -99,6 +99,7 @@ constexpr const char* const DefaultBackoffConfig = "E,3000,300000,2,1"; mutable std::mutex m_activeUploads_lock; std::set m_activeUploads; + std::chrono::steady_clock::time_point otherPriorityLastExecutionTime; /// /// Thread-safe method to add the upload to active uploads. From c19c6941f6f1d1d216895b23440b1f4f4d753b0c Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Mon, 18 Sep 2023 02:24:23 -0700 Subject: [PATCH 09/24] Fix --- lib/tpm/TransmissionPolicyManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 95771a85e..b11875748 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -357,7 +357,7 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. - if (other_priority_elapsed_seconds > 40 && m_isUploadScheduled.load()){ + if ((other_priority_elapsed_seconds > 40) && m_isUploadScheduled){ m_isUploadScheduled.exchange(false); LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; From fe45d0035fbde1117696f48e9d12cc30e4037d59 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 16:41:48 -0700 Subject: [PATCH 10/24] Test Event Arrived m_isUploadScheduled --- lib/tpm/TransmissionPolicyManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index b11875748..fe370abd5 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -497,6 +497,7 @@ namespace MAT_NS_BEGIN { { LOG_TRACE("Reset upload on event cancellation"); } + otherPriorityLastExecutionTime = currentTime; } return result; From 583e083306f68c7d4dd8f4343a59652077cebbc7 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 16:45:02 -0700 Subject: [PATCH 11/24] Test Event Arrived m_isUploadScheduled --- lib/tpm/TransmissionPolicyManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index fe370abd5..54c2e732b 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -358,7 +358,6 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. if ((other_priority_elapsed_seconds > 40) && m_isUploadScheduled){ - m_isUploadScheduled.exchange(false); LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } From da5994410f98489c428e07378242e4e44b5e379e Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 16:46:46 -0700 Subject: [PATCH 12/24] Test Cancel and Event Arrived m_isUploadScheduled --- lib/tpm/TransmissionPolicyManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 54c2e732b..8560ee902 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -491,7 +491,6 @@ namespace MAT_NS_BEGIN { // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. if (result || other_priority_elapsed_seconds > 40) { - m_isUploadScheduled.exchange(false); if (other_priority_elapsed_seconds > 40) { LOG_TRACE("Reset upload on event cancellation"); From d2173160dafb75d0f85f96bb39aa04c8295975c0 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 18:54:33 -0700 Subject: [PATCH 13/24] Test Event Arrived m_isUploadScheduled false --- lib/tpm/TransmissionPolicyManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 8560ee902..0943d2c59 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -358,6 +358,7 @@ namespace MAT_NS_BEGIN { // Introducing a 40-second delay before forcefully scheduling the upload job, to ensure it happens at an optimal time. // This delay is implemented to address Issue 388, where the last cancellation might have been halted due to the issue described below. if ((other_priority_elapsed_seconds > 40) && m_isUploadScheduled){ + m_isUploadScheduled = false; LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } From 16d160530eb7f2537d430cb5252380656753c726 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 20:08:56 -0700 Subject: [PATCH 14/24] Remove constructor initialization --- lib/tpm/TransmissionPolicyManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 0943d2c59..63c38f6a4 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -52,7 +52,6 @@ namespace MAT_NS_BEGIN { m_backoff = IBackoff::createFromConfig(m_backoffConfig); assert(m_backoff); m_deviceStateHandler.Start(); - otherPriorityLastExecutionTime = std::chrono::steady_clock::now(); } TransmissionPolicyManager::~TransmissionPolicyManager() From 02ce67a858e2efe6456930e64a6375febab871c5 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 20:52:05 -0700 Subject: [PATCH 15/24] Add timer exception --- lib/tpm/TransmissionPolicyManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 63c38f6a4..ab39424f0 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -351,6 +351,8 @@ namespace MAT_NS_BEGIN { return; } +// Currently MIP SDK does not have any solution for MAC OS hence blocking this code for Apple since it was blocking some MIP SDK' test (oneds_test.cpp) just for MAC OS due timeout. +#ifndef __APPLE__ // Other priorities like: Normal, Realtime, etc. auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); @@ -361,7 +363,7 @@ namespace MAT_NS_BEGIN { LOG_TRACE("Trigger upload on event arrival"); otherPriorityLastExecutionTime = currentTime; } - +#endif // Schedule async upload if not scheduled yet if (!m_isUploadScheduled || TransmitProfiles::isTimerUpdateRequired()) { From fe8220e8ef3363aec6c4fb3d057cb9675a3fd200 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 21:54:10 -0700 Subject: [PATCH 16/24] Fix MacOS issue --- lib/tpm/TransmissionPolicyManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index ab39424f0..45b580966 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -52,6 +52,7 @@ namespace MAT_NS_BEGIN { m_backoff = IBackoff::createFromConfig(m_backoffConfig); assert(m_backoff); m_deviceStateHandler.Start(); + otherPriorityLastExecutionTime = std::chrono::steady_clock::now(); } TransmissionPolicyManager::~TransmissionPolicyManager() @@ -351,7 +352,8 @@ namespace MAT_NS_BEGIN { return; } -// Currently MIP SDK does not have any solution for MAC OS hence blocking this code for Apple since it was blocking some MIP SDK' test (oneds_test.cpp) just for MAC OS due timeout. +// Currently MIP SDK does not have any solution for MacOS which generates auditing hence temporarily blocking this temporary code fix for inconsistent OneDS upload thread +// stoppage issue in Apple env since it was blocking some MIP SDK's test (oneds_test.cpp) just for MAC OS due timeout. This block could be removed after validation. #ifndef __APPLE__ // Other priorities like: Normal, Realtime, etc. auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); From 38605c561f152b9e0917c76d0d639a46c05d70bc Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 19 Sep 2023 21:57:39 -0700 Subject: [PATCH 17/24] Fix comment --- lib/tpm/TransmissionPolicyManager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 45b580966..297d352c4 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -352,8 +352,10 @@ namespace MAT_NS_BEGIN { return; } -// Currently MIP SDK does not have any solution for MacOS which generates auditing hence temporarily blocking this temporary code fix for inconsistent OneDS upload thread -// stoppage issue in Apple env since it was blocking some MIP SDK's test (oneds_test.cpp) just for MAC OS due timeout. This block could be removed after validation. +// This code block is temporarily disabled for MacOS because the MIP SDK lacks a solution for auditing on MacOS. +// This temporary code fix was introduced to address an issue with inconsistent OneDS upload thread stoppage in all environments especially for Windows. +// It was blocking some of the MIP SDK's tests (oneds_test.cpp) on MacOS due to timeouts. +// This block can be removed after validation. #ifndef __APPLE__ // Other priorities like: Normal, Realtime, etc. auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); From 77ce08d6826cfd066ea5e1fe486f7aaa451fb63a Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Wed, 20 Sep 2023 17:09:52 -0700 Subject: [PATCH 18/24] Test Mac fix --- lib/tpm/TransmissionPolicyManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 297d352c4..fd5a16d51 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -501,7 +501,7 @@ namespace MAT_NS_BEGIN { { LOG_TRACE("Reset upload on event cancellation"); } - + m_isUploadScheduled.exchange(false); otherPriorityLastExecutionTime = currentTime; } return result; From 0b7c2e307e218ace686ac85e31fb1b862692288a Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Wed, 20 Sep 2023 21:02:38 -0700 Subject: [PATCH 19/24] Validate other flags --- lib/tpm/TransmissionPolicyManager.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index fd5a16d51..2269e9f31 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -356,7 +356,7 @@ namespace MAT_NS_BEGIN { // This temporary code fix was introduced to address an issue with inconsistent OneDS upload thread stoppage in all environments especially for Windows. // It was blocking some of the MIP SDK's tests (oneds_test.cpp) on MacOS due to timeouts. // This block can be removed after validation. -#ifndef __APPLE__ +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(_WIN64) || defined(__linux__) || defined(__ANDROID__) // Other priorities like: Normal, Realtime, etc. auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); @@ -484,7 +484,7 @@ namespace MAT_NS_BEGIN { bool TransmissionPolicyManager::cancelUploadTask() { bool result = m_scheduledUpload.Cancel(getCancelWaitTime().count()); - +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(_WIN64) || defined(__linux__) || defined(__ANDROID__) // Check if it's time to execute the specific code block auto currentTime = std::chrono::steady_clock::now(); @@ -504,6 +504,12 @@ namespace MAT_NS_BEGIN { m_isUploadScheduled.exchange(false); otherPriorityLastExecutionTime = currentTime; } +#else + if (result) + { + m_isUploadScheduled.exchange(false); + } +#endif return result; } From 393b695ce0fef65a170859100892947ae642ecc3 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Wed, 20 Sep 2023 22:40:17 -0700 Subject: [PATCH 20/24] Test --- lib/tpm/TransmissionPolicyManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 2269e9f31..3a792513a 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -356,7 +356,7 @@ namespace MAT_NS_BEGIN { // This temporary code fix was introduced to address an issue with inconsistent OneDS upload thread stoppage in all environments especially for Windows. // It was blocking some of the MIP SDK's tests (oneds_test.cpp) on MacOS due to timeouts. // This block can be removed after validation. -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(_WIN64) || defined(__linux__) || defined(__ANDROID__) +#if !defined(__APPLE__) // Other priorities like: Normal, Realtime, etc. auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); @@ -484,7 +484,7 @@ namespace MAT_NS_BEGIN { bool TransmissionPolicyManager::cancelUploadTask() { bool result = m_scheduledUpload.Cancel(getCancelWaitTime().count()); -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(_WIN64) || defined(__linux__) || defined(__ANDROID__) +#if !defined(__APPLE__) // Check if it's time to execute the specific code block auto currentTime = std::chrono::steady_clock::now(); From 49da9e2fe8c22ed56b6f348f6751019bae0d6ea4 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Thu, 21 Sep 2023 00:00:48 -0700 Subject: [PATCH 21/24] Validate 57 --- lib/tpm/TransmissionPolicyManager.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 3a792513a..c919403b4 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -484,7 +484,6 @@ namespace MAT_NS_BEGIN { bool TransmissionPolicyManager::cancelUploadTask() { bool result = m_scheduledUpload.Cancel(getCancelWaitTime().count()); -#if !defined(__APPLE__) // Check if it's time to execute the specific code block auto currentTime = std::chrono::steady_clock::now(); @@ -504,12 +503,6 @@ namespace MAT_NS_BEGIN { m_isUploadScheduled.exchange(false); otherPriorityLastExecutionTime = currentTime; } -#else - if (result) - { - m_isUploadScheduled.exchange(false); - } -#endif return result; } From f5c80635fd0fbc5f6a78594a8225a0ac47fd66ee Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Thu, 21 Sep 2023 02:47:53 -0700 Subject: [PATCH 22/24] Validate 58 --- lib/tpm/TransmissionPolicyManager.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index c919403b4..18a4c3d6f 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -356,7 +356,7 @@ namespace MAT_NS_BEGIN { // This temporary code fix was introduced to address an issue with inconsistent OneDS upload thread stoppage in all environments especially for Windows. // It was blocking some of the MIP SDK's tests (oneds_test.cpp) on MacOS due to timeouts. // This block can be removed after validation. -#if !defined(__APPLE__) +#ifndef __APPLE__ // Other priorities like: Normal, Realtime, etc. auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); @@ -484,6 +484,7 @@ namespace MAT_NS_BEGIN { bool TransmissionPolicyManager::cancelUploadTask() { bool result = m_scheduledUpload.Cancel(getCancelWaitTime().count()); +#ifndef __APPLE__ // Check if it's time to execute the specific code block auto currentTime = std::chrono::steady_clock::now(); @@ -503,6 +504,12 @@ namespace MAT_NS_BEGIN { m_isUploadScheduled.exchange(false); otherPriorityLastExecutionTime = currentTime; } +#else + if (result) + { + m_isUploadScheduled.exchange(false); + } +#endif return result; } From 00b3b5ee887c9c74dc9000ac495dc05859237d3b Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 10 Oct 2023 15:10:15 -0700 Subject: [PATCH 23/24] Validate 59 --- lib/tpm/TransmissionPolicyManager.cpp | 6 ++++-- lib/tpm/TransmissionPolicyManager.hpp | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 18a4c3d6f..34757af94 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -335,6 +335,7 @@ namespace MAT_NS_BEGIN { // Check if it's time to execute the specific Max or other priority events code block auto currentTime = std::chrono::steady_clock::now(); static auto maxPriorityLastExecutionTime = currentTime; + static auto otherPriorityLastExecutionTime = currentTime; auto max_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - maxPriorityLastExecutionTime).count(); @@ -487,8 +488,9 @@ namespace MAT_NS_BEGIN { #ifndef __APPLE__ // Check if it's time to execute the specific code block auto currentTime = std::chrono::steady_clock::now(); + static auto otherPriorityLastExecutionTimeClock = currentTime; - auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTime).count(); + auto other_priority_elapsed_seconds = std::chrono::duration_cast(currentTime - otherPriorityLastExecutionTimeClock).count(); // TODO: There is a potential for upload tasks to not be canceled, especially if they aren't waited for. // We either need a stronger guarantee here (could impact SDK performance), or a mechanism to @@ -502,7 +504,7 @@ namespace MAT_NS_BEGIN { LOG_TRACE("Reset upload on event cancellation"); } m_isUploadScheduled.exchange(false); - otherPriorityLastExecutionTime = currentTime; + otherPriorityLastExecutionTimeClock = currentTime; } #else if (result) diff --git a/lib/tpm/TransmissionPolicyManager.hpp b/lib/tpm/TransmissionPolicyManager.hpp index 7bf6a7549..eb2bd4b34 100644 --- a/lib/tpm/TransmissionPolicyManager.hpp +++ b/lib/tpm/TransmissionPolicyManager.hpp @@ -99,7 +99,6 @@ constexpr const char* const DefaultBackoffConfig = "E,3000,300000,2,1"; mutable std::mutex m_activeUploads_lock; std::set m_activeUploads; - std::chrono::steady_clock::time_point otherPriorityLastExecutionTime; /// /// Thread-safe method to add the upload to active uploads. From 84d39fb3aa69291541589a86459dafa79fc2c545 Mon Sep 17 00:00:00 2001 From: Shiv Pratap Singh Date: Tue, 10 Oct 2023 15:21:21 -0700 Subject: [PATCH 24/24] build fix --- lib/tpm/TransmissionPolicyManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tpm/TransmissionPolicyManager.cpp b/lib/tpm/TransmissionPolicyManager.cpp index 34757af94..af728aca8 100644 --- a/lib/tpm/TransmissionPolicyManager.cpp +++ b/lib/tpm/TransmissionPolicyManager.cpp @@ -52,7 +52,6 @@ namespace MAT_NS_BEGIN { m_backoff = IBackoff::createFromConfig(m_backoffConfig); assert(m_backoff); m_deviceStateHandler.Start(); - otherPriorityLastExecutionTime = std::chrono::steady_clock::now(); } TransmissionPolicyManager::~TransmissionPolicyManager()