summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-01-29 00:05:49 +0100
committerChristian Grothoff <christian@grothoff.org>2024-01-29 00:05:49 +0100
commit39678f88d5a1270f723a79986bf197a33e7d0424 (patch)
tree3470712f2bfb2ad4b598b615f0023a0360e8bd57
parent417af3ad417198a5087306d5f0f959473ed8399e (diff)
downloadmerchant-39678f88d5a1270f723a79986bf197a33e7d0424.tar.gz
merchant-39678f88d5a1270f723a79986bf197a33e7d0424.tar.bz2
merchant-39678f88d5a1270f723a79986bf197a33e7d0424.zip
dynamically adjust long-polling threshold if we get gateway timeouts
-rw-r--r--src/backend/taler-merchant-wirewatch.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/backend/taler-merchant-wirewatch.c b/src/backend/taler-merchant-wirewatch.c
index 075bdfa4..77428da3 100644
--- a/src/backend/taler-merchant-wirewatch.c
+++ b/src/backend/taler-merchant-wirewatch.c
@@ -34,6 +34,7 @@
#define BANK_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, \
5)
+
/**
* Information about a watch job.
*/
@@ -55,6 +56,11 @@ struct Watch
struct GNUNET_SCHEDULER_Task *task;
/**
+ * Dynamically adjusted long polling time-out.
+ */
+ struct GNUNET_TIME_Relative bank_timeout;
+
+ /**
* For which instance are we importing bank transfers?
*/
char *instance_id;
@@ -81,6 +87,11 @@ struct Watch
struct GNUNET_TIME_Relative delay;
/**
+ * When did we start our last HTTP request?
+ */
+ struct GNUNET_TIME_Absolute start_time;
+
+ /**
* How long should long-polling take at least?
*/
struct GNUNET_TIME_Absolute long_poll_timeout;
@@ -415,6 +426,23 @@ credit_cb (
GNUNET_TIME_relative2s (w->delay,
true));
break;
+ case MHD_HTTP_GATEWAY_TIMEOUT:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Gateway timeout, adjusting long polling threshold\n");
+ /* Limit new timeout at request delay */
+ w->bank_timeout
+ = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_duration (
+ w->start_time),
+ w->bank_timeout);
+ /* set the timeout a bit earlier */
+ w->bank_timeout
+ = GNUNET_TIME_relative_subtract (w->bank_timeout,
+ GNUNET_TIME_UNIT_SECONDS);
+ /* do not allow it to go to zero */
+ w->bank_timeout
+ = GNUNET_TIME_relative_max (w->bank_timeout,
+ GNUNET_TIME_UNIT_SECONDS);
+ w->delay = GNUNET_TIME_STD_BACKOFF (w->delay);
default:
/* Something went wrong, try again, but with back-off */
w->delay = GNUNET_TIME_STD_BACKOFF (w->delay);
@@ -449,14 +477,16 @@ do_work (void *cls)
w->task = NULL;
w->found = false;
w->long_poll_timeout
- = GNUNET_TIME_relative_to_absolute (BANK_TIMEOUT);
+ = GNUNET_TIME_relative_to_absolute (w->bank_timeout);
+ w->start_time
+ = GNUNET_TIME_absolute_get ();
w->hh = TALER_MERCHANT_BANK_credit_history (ctx,
&w->ad,
w->start_row,
batch_size,
test_mode
? GNUNET_TIME_UNIT_ZERO
- : BANK_TIMEOUT,
+ : w->bank_timeout,
&credit_cb,
w);
if (NULL == w->hh)
@@ -491,6 +521,7 @@ start_watch (
struct Watch *w = GNUNET_new (struct Watch);
(void) cls;
+ w->bank_timeout = BANK_TIMEOUT;
if (GNUNET_OK !=
TALER_MERCHANT_BANK_auth_parse_json (credit_facade_credentials,
credit_facade_url,