diff --git a/glean-core/csharp/Glean/Net/BaseUploader.cs b/glean-core/csharp/Glean/Net/BaseUploader.cs index 4f96841463..0111daaa82 100644 --- a/glean-core/csharp/Glean/Net/BaseUploader.cs +++ b/glean-core/csharp/Glean/Net/BaseUploader.cs @@ -19,6 +19,7 @@ namespace Mozilla.Glean.Net /// internal class BaseUploader { + internal const int THROTTLED_BACKOFF_MS = 60_000; private readonly IPingUploader uploader; /// @@ -88,8 +89,6 @@ internal void TriggerUpload(Configuration config) // TODO: must not work like this, it should work off the main thread. // FOR TESTING Implement the upload worker here and call this from Glean.cs - int waitAttempts = 0; - // Limits are enforced by glean-core to avoid an inifinite loop here. // Whenever a limit is reached, this binding will receive `UploadTaskTag.Done` and step out. while (true) @@ -126,7 +125,7 @@ internal void TriggerUpload(Configuration config) } break; case UploadTaskTag.Wait: - Thread.Sleep(100); + Thread.Sleep(THROTTLED_BACKOFF_MS); break; case UploadTaskTag.Done: // Nothing to do here, break out of the loop. diff --git a/glean-core/ios/Glean/Net/HttpPingUploader.swift b/glean-core/ios/Glean/Net/HttpPingUploader.swift index 8213472c50..df5fef5aad 100644 --- a/glean-core/ios/Glean/Net/HttpPingUploader.swift +++ b/glean-core/ios/Glean/Net/HttpPingUploader.swift @@ -13,6 +13,7 @@ public class HttpPingUploader { // Since ping file names are UUIDs, this matches UUIDs for filtering purposes static let logTag = "glean/HttpPingUploader" static let connectionTimeout = 10000 + static let throttleBackoffMs: UInt32 = 60_000 // For this error, the ping will be retried later static let recoverableErrorStatusCode: UInt16 = 500 @@ -108,6 +109,7 @@ public class HttpPingUploader { glean_process_ping_upload_response(&incomingTask, result.toFfi()) } case .wait: + sleep(Constants.throttleBackoffMs) continue case .done: return diff --git a/glean-core/python/glean/glean.py b/glean-core/python/glean/glean.py index 1f901b5078..e3e31ac814 100644 --- a/glean-core/python/glean/glean.py +++ b/glean-core/python/glean/glean.py @@ -230,6 +230,9 @@ def _initialize_with_tempdir_for_testing( The temporary directory will be destroyed when Glean is initialized again or at process shutdown. """ + # Lower throttle backoff time for testing + PingUploadWorker._throttle_backoff_time = 1 + actual_data_dir = Path(tempfile.TemporaryDirectory().name) cls.initialize( application_id, diff --git a/glean-core/python/glean/net/ping_upload_worker.py b/glean-core/python/glean/net/ping_upload_worker.py index 04c69f8e36..4c98343950 100644 --- a/glean-core/python/glean/net/ping_upload_worker.py +++ b/glean-core/python/glean/net/ping_upload_worker.py @@ -23,6 +23,8 @@ class PingUploadWorker: + _throttle_backoff_time = 60_000 + @classmethod def process(cls): """ @@ -43,7 +45,13 @@ def _process(cls): from .. import Glean return ProcessDispatcher.dispatch( - _process, (Glean._data_dir, Glean._application_id, Glean._configuration) + _process, + ( + Glean._data_dir, + Glean._application_id, + Glean._configuration, + cls._throttle_backoff_time, + ), ) @classmethod @@ -94,7 +102,9 @@ def _parse_ping_headers( return headers -def _process(data_dir: Path, application_id: str, configuration) -> bool: +def _process( + data_dir: Path, application_id: str, configuration, throttle_backoff_time: int +) -> bool: # Import here to avoid cyclical import from ..glean import Glean @@ -144,7 +154,7 @@ def _process(data_dir: Path, application_id: str, configuration) -> bool: incoming_task, upload_result.to_ffi() ) elif tag == UploadTaskTag.WAIT: - time.sleep(1) + time.sleep(throttle_backoff_time) elif tag == UploadTaskTag.DONE: return True diff --git a/glean-core/python/tests/test_glean.py b/glean-core/python/tests/test_glean.py index 1df3b73432..92206b7edb 100644 --- a/glean-core/python/tests/test_glean.py +++ b/glean-core/python/tests/test_glean.py @@ -37,7 +37,6 @@ from glean.net import PingUploadWorker from glean.testing import _RecordingUploader - GLEAN_APP_ID = "glean-python-test"