diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-02-02 09:23:14 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-02 09:23:14 +0100 |
commit | 8b50f8e0e37f69a806822df83bc20c9e964dd6d8 (patch) | |
tree | 401f25659ccef32ce32bc96698089606399a9100 /src/backend/taler-merchant-httpd_private-get-orders-ID.c | |
parent | 152b9b98282419937af410f53837bb7d3590c9a0 (diff) | |
download | merchant-8b50f8e0e37f69a806822df83bc20c9e964dd6d8.tar.gz merchant-8b50f8e0e37f69a806822df83bc20c9e964dd6d8.tar.bz2 merchant-8b50f8e0e37f69a806822df83bc20c9e964dd6d8.zip |
fix various cases where shutdown did not work if long pollers were present (#7166)
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-orders-ID.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders-ID.c | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index b4067f56..5cfba15e 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2017-2021 Taler Systems SA + (C) 2017-2022 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -259,9 +259,13 @@ struct GetOrderRequestContext unsigned int wire_hc; /** - * Set to true if this request is currently suspended. + * Did we suspend @a connection and are thus in + * the #gorc_head DLL (#GNUNET_YES). Set to + * #GNUNET_NO if we are not suspended, and to + * #GNUNET_SYSERR if we should close the connection + * without a response due to shutdown. */ - bool suspended; + enum GNUNET_GenericReturnValue suspended; /** * Set to true if this payment has been refunded and @@ -295,6 +299,23 @@ static struct GetOrderRequestContext *gorc_head; static struct GetOrderRequestContext *gorc_tail; +void +TMH_force_gorc_resume (void) +{ + struct GetOrderRequestContext *gorc; + + while (NULL != (gorc = gorc_head)) + { + GNUNET_CONTAINER_DLL_remove (gorc_head, + gorc_tail, + gorc); + GNUNET_assert (GNUNET_YES == gorc->suspended); + gorc->suspended = GNUNET_SYSERR; + MHD_resume_connection (gorc->sc.con); + } +} + + /** * Resume processing the request, cancelling all pending asynchronous * operations. @@ -330,11 +351,11 @@ gorc_resume (struct GetOrderRequestContext *gorc, } gorc->wire_hc = http_status; gorc->wire_ec = ec; - GNUNET_assert (gorc->suspended); + GNUNET_assert (GNUNET_YES == gorc->suspended); GNUNET_CONTAINER_DLL_remove (gorc_head, gorc_tail, gorc); - gorc->suspended = false; + gorc->suspended = GNUNET_NO; MHD_resume_connection (gorc->sc.con); TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ } @@ -360,9 +381,9 @@ resume_by_event (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Resuming request %p by trigger\n", gorc); - if (! gorc->suspended) + if (GNUNET_NO == gorc->suspended) return; /* duplicate event is possible */ - gorc->suspended = false; + gorc->suspended = GNUNET_NO; GNUNET_CONTAINER_DLL_remove (gorc_head, gorc_tail, gorc); @@ -965,10 +986,11 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, gorc->sc.long_poll_timeout = GNUNET_TIME_UNIT_ZERO_ABS; } } - - } /* end first-time per-request initialization */ + if (GNUNET_SYSERR == gorc->suspended) + return MHD_NO; /* we are in shutdown */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting GET /private/orders/%s processing with timeout %s\n", hc->infix, @@ -1229,7 +1251,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, GNUNET_CONTAINER_DLL_insert (gorc_head, gorc_tail, gorc); - gorc->suspended = true; + gorc->suspended = GNUNET_YES; MHD_suspend_connection (gorc->sc.con); return MHD_YES; } @@ -1265,7 +1287,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, GNUNET_CONTAINER_DLL_insert (gorc_head, gorc_tail, gorc); - gorc->suspended = true; + gorc->suspended = GNUNET_YES; MHD_suspend_connection (connection); gorc->tt = GNUNET_SCHEDULER_add_delayed (EXCHANGE_TIMEOUT, &exchange_timeout_cb, @@ -1280,11 +1302,11 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending GET /private/orders/%s\n", hc->infix); - GNUNET_assert (! gorc->suspended); + GNUNET_assert (GNUNET_NO == gorc->suspended); GNUNET_CONTAINER_DLL_insert (gorc_head, gorc_tail, gorc); - gorc->suspended = true; + gorc->suspended = GNUNET_YES; MHD_suspend_connection (gorc->sc.con); return MHD_YES; } |