From 79e1be43beeb0af7509673ac505048c0eac9c214 Mon Sep 17 00:00:00 2001 From: Matias Pequeno Date: Wed, 10 Aug 2022 13:11:52 -0300 Subject: [PATCH 1/2] Suspend http transactions for 30 seconds in case of failure --- rollbar_dart/lib/src/sender/http_sender.dart | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rollbar_dart/lib/src/sender/http_sender.dart b/rollbar_dart/lib/src/sender/http_sender.dart index 0a3281e..afad512 100644 --- a/rollbar_dart/lib/src/sender/http_sender.dart +++ b/rollbar_dart/lib/src/sender/http_sender.dart @@ -39,6 +39,13 @@ class HttpSender implements Sender { @override Future sendString(String payload) async { try { + if (_State.suspended) { + throw HttpException( + 'HTTP transactions are currently suspended.', + uri: _endpoint, + ); + } + final response = await http .post(_endpoint, headers: _headers, body: payload) .then(Response.from); @@ -52,6 +59,8 @@ class HttpSender implements Sender { return true; } catch (error, stackTrace) { + _State.suspend(30.seconds); + log('Exception sending payload', time: DateTime.now(), level: Level.error.value, @@ -63,3 +72,16 @@ class HttpSender implements Sender { } } } + +extension _State on HttpSender { + static bool _suspended = false; + + static bool get suspended => _suspended; + + static void suspend(Duration duration) async { + if (_suspended) return; + _suspended = true; + await Future.delayed(duration); + _suspended = false; + } +} From 8361ec120fd7facaf524f8ecdec5b9ba106e0546 Mon Sep 17 00:00:00 2001 From: Matias Pequeno Date: Wed, 10 Aug 2022 13:30:40 -0300 Subject: [PATCH 2/2] Clarify we only suspend if not suspended already --- rollbar_dart/lib/src/sender/http_sender.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollbar_dart/lib/src/sender/http_sender.dart b/rollbar_dart/lib/src/sender/http_sender.dart index afad512..1ddbed0 100644 --- a/rollbar_dart/lib/src/sender/http_sender.dart +++ b/rollbar_dart/lib/src/sender/http_sender.dart @@ -59,7 +59,7 @@ class HttpSender implements Sender { return true; } catch (error, stackTrace) { - _State.suspend(30.seconds); + if (!_State.suspended) _State.suspend(30.seconds); log('Exception sending payload', time: DateTime.now(),