gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: implement POST reserves timeout


From: gnunet
Subject: [taler-merchant] branch master updated: implement POST reserves timeout (#6875)
Date: Mon, 17 May 2021 21:55:11 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 38e0c530 implement POST reserves timeout (#6875)
38e0c530 is described below

commit 38e0c53097a6df0033a35ba90f712b3c89571a98
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon May 17 21:55:08 2021 +0200

    implement POST reserves timeout (#6875)
---
 .../taler-merchant-httpd_private-post-reserves.c   | 63 +++++++++++++++++++++-
 .../taler-merchant-httpd_private-post-transfers.c  |  2 +-
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-reserves.c 
b/src/backend/taler-merchant-httpd_private-post-reserves.c
index 095264d3..b2cc14c6 100644
--- a/src/backend/taler-merchant-httpd_private-post-reserves.c
+++ b/src/backend/taler-merchant-httpd_private-post-reserves.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  (C) 2020 Taler Systems SA
+  (C) 2021 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as
@@ -29,6 +29,14 @@
 #include <taler/taler_json_lib.h>
 
 
+/**
+ * How long to wait before giving up processing with the exchange?
+ */
+#define EXCHANGE_GENERIC_TIMEOUT (GNUNET_TIME_relative_multiply ( \
+                                    GNUNET_TIME_UNIT_SECONDS, \
+                                    15))
+
+
 /**
  * Information we keep for an individual call to the POST /reserves handler.
  */
@@ -75,6 +83,11 @@ struct PostReserveContext
    */
   struct TMH_EXCHANGES_FindOperation *fo;
 
+  /**
+   * Task run on timeout.
+   */
+  struct GNUNET_SCHEDULER_Task *timeout_task;
+
   /**
    * Initial balance of the reserve.
    */
@@ -127,6 +140,11 @@ TMH_force_rc_resume ()
        rc = rcn)
   {
     rcn = rc->next;
+    if (NULL != rc->timeout_task)
+    {
+      GNUNET_SCHEDULER_cancel (rc->timeout_task);
+      rc->timeout_task = NULL;
+    }
     if (rc->suspended)
     {
       rc->suspended = false;
@@ -159,6 +177,11 @@ reserve_context_cleanup (void *cls)
     TMH_EXCHANGES_find_exchange_cancel (rc->fo);
     rc->fo = NULL;
   }
+  if (NULL != rc->timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel (rc->timeout_task);
+    rc->timeout_task = NULL;
+  }
   GNUNET_assert (! rc->suspended);
   GNUNET_free (rc->payto_uri);
   GNUNET_free (rc);
@@ -189,6 +212,11 @@ handle_exchange (void *cls,
 
   rc->fo = NULL;
   rc->suspended = false;
+  if (NULL != rc->timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel (rc->timeout_task);
+    rc->timeout_task = NULL;
+  }
   MHD_resume_connection (rc->connection);
   GNUNET_CONTAINER_DLL_remove (rc_head,
                                rc_tail,
@@ -229,6 +257,35 @@ handle_exchange (void *cls,
 }
 
 
+/**
+ * Handle a timeout for the processing of the wire request.
+ *
+ * @param cls closure
+ */
+static void
+handle_exchange_timeout (void *cls)
+{
+  struct PostReserveContext *rc = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Resuming POST /private/reserves with error after timeout\n");
+  rc->timeout_task = NULL;
+  if (NULL != rc->fo)
+  {
+    TMH_EXCHANGES_find_exchange_cancel (rc->fo);
+    rc->fo = NULL;
+  }
+  rc->suspended = false;
+  MHD_resume_connection (rc->connection);
+  GNUNET_CONTAINER_DLL_remove (rc_head,
+                               rc_tail,
+                               rc);
+  rc->ec = TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT;
+  rc->http_status = MHD_HTTP_GATEWAY_TIMEOUT;
+  TMH_trigger_daemon ();   /* we resumed, kick MHD */
+}
+
+
 MHD_RESULT
 TMH_private_post_reserves (const struct TMH_RequestHandler *rh,
                            struct MHD_Connection *connection,
@@ -283,6 +340,10 @@ TMH_private_post_reserves (const struct TMH_RequestHandler 
*rh,
                                           GNUNET_NO,
                                           &handle_exchange,
                                           rc);
+    rc->timeout_task
+      = GNUNET_SCHEDULER_add_delayed (EXCHANGE_GENERIC_TIMEOUT,
+                                      &handle_exchange_timeout,
+                                      rc);
     rc->suspended = true;
     GNUNET_CONTAINER_DLL_insert (rc_head,
                                  rc_tail,
diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c 
b/src/backend/taler-merchant-httpd_private-post-transfers.c
index 76f86ce2..4fd0819d 100644
--- a/src/backend/taler-merchant-httpd_private-post-transfers.c
+++ b/src/backend/taler-merchant-httpd_private-post-transfers.c
@@ -33,7 +33,7 @@
  */
 #define TRANSFER_GENERIC_TIMEOUT (GNUNET_TIME_relative_multiply ( \
                                     GNUNET_TIME_UNIT_SECONDS, \
-                                    1))
+                                    15))
 
 /**
  * How often do we retry the simple INSERT database transaction?

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]