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 | |
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')
7 files changed, 102 insertions, 48 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index f2de7373..4ee65ef4 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2021 Taler Systems SA + (C) 2014-2022 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 published by the Free Software diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index d6abdc62..9748f469 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2021 Taler Systems SA + (C) 2014-2022 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 published by the Free Software @@ -131,9 +131,12 @@ struct GetOrderData /** * Did we suspend @a connection and are thus in - * the #god_head DLL? + * the #god_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 we are dealing with a claimed order @@ -184,7 +187,7 @@ TMH_force_wallet_get_order_resume (void) god_tail, god); GNUNET_assert (god->suspended); - god->suspended = false; + god->suspended = GNUNET_SYSERR; MHD_resume_connection (god->sc.con); TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ } @@ -267,7 +270,7 @@ resume_by_event (void *cls, god->sc.awaiting_refund, (int) extra_size, (const char *) extra); - god->suspended = false; + god->suspended = GNUNET_NO; GNUNET_CONTAINER_DLL_remove (god_head, god_tail, god); @@ -295,7 +298,7 @@ suspend_god (struct GetOrderData *god) god->contract_terms = NULL; } GNUNET_assert (! god->suspended); - god->suspended = true; + god->suspended = GNUNET_YES; GNUNET_CONTAINER_DLL_insert (god_head, god_tail, god); @@ -1003,9 +1006,11 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, } /* end of first-time initialization / sanity checks */ - if (god->suspended) + if (GNUNET_SYSERR == god->suspended) + return MHD_NO; /* we are in shutdown */ + if (GNUNET_YES == god->suspended) { - god->suspended = false; + god->suspended = GNUNET_NO; GNUNET_CONTAINER_DLL_remove (god_head, god_tail, god); diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-refund.c b/src/backend/taler-merchant-httpd_post-orders-ID-refund.c index c6011d21..80bbbfa8 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-refund.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-refund.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2020-2021 Taler Systems SA + (C) 2020-2022 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 @@ -201,9 +201,13 @@ struct PostRefundData struct TALER_Amount refund_amount; /** - * Did we suspend @a connection? + * Did we suspend @a connection and are thus in + * the #prd_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; /** * Return code: #TALER_EC_NONE if successful. @@ -304,7 +308,7 @@ TMH_force_wallet_refund_order_resume (void) prd_tail, prd); GNUNET_assert (prd->suspended); - prd->suspended = false; + prd->suspended = GNUNET_SYSERR; MHD_resume_connection (prd->sc.con); } } @@ -346,7 +350,7 @@ check_resume_prd (struct PostRefundData *prd) prd_tail, prd); GNUNET_assert (prd->suspended); - prd->suspended = false; + prd->suspended = GNUNET_NO; MHD_resume_connection (prd->sc.con); TALER_MHD_daemon_trigger (); } @@ -646,6 +650,8 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh, } } } + if (GNUNET_SYSERR == prd->suspended) + return MHD_NO; /* we are in shutdown */ if (TALER_EC_NONE != prd->ec) { @@ -733,9 +739,9 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh, /* Check if there are still exchange operations pending */ if (exchange_operations_pending (prd)) { - if (! prd->suspended) + if (GNUNET_NO == prd->suspended) { - prd->suspended = true; + prd->suspended = GNUNET_YES; MHD_suspend_connection (connection); GNUNET_CONTAINER_DLL_insert (prd_head, prd_tail, 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; } diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.h b/src/backend/taler-merchant-httpd_private-get-orders-ID.h index af7f7938..8c118519 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.h +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.h @@ -38,4 +38,12 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, struct MHD_Connection *connection, struct TMH_HandlerContext *hc); + +/** + * Force resuming all long polling GET orders ID requests, we are shutting + * down. + */ +void +TMH_force_gorc_resume (void); + #endif diff --git a/src/backend/taler-merchant-httpd_private-post-reserves.c b/src/backend/taler-merchant-httpd_private-post-reserves.c index 37b887ef..0351ab10 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) 2021 Taler Systems SA + (C) 2021, 2022 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 @@ -109,9 +109,13 @@ struct PostReserveContext enum TALER_ErrorCode ec; /** - * Are we suspended? + * Did we suspend @a connection and are thus in + * the #rc_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; }; @@ -145,9 +149,9 @@ TMH_force_rc_resume () GNUNET_SCHEDULER_cancel (rc->timeout_task); rc->timeout_task = NULL; } - if (rc->suspended) + if (GNUNET_YES == rc->suspended) { - rc->suspended = false; + rc->suspended = GNUNET_SYSERR; MHD_resume_connection (rc->connection); GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, @@ -182,7 +186,7 @@ reserve_context_cleanup (void *cls) GNUNET_SCHEDULER_cancel (rc->timeout_task); rc->timeout_task = NULL; } - GNUNET_assert (! rc->suspended); + GNUNET_assert (GNUNET_YES != rc->suspended); GNUNET_free (rc->payto_uri); GNUNET_free (rc); } @@ -211,12 +215,12 @@ handle_exchange (void *cls, const struct TALER_EXCHANGE_Keys *keys; rc->fo = NULL; - rc->suspended = false; if (NULL != rc->timeout_task) { GNUNET_SCHEDULER_cancel (rc->timeout_task); rc->timeout_task = NULL; } + rc->suspended = GNUNET_NO; MHD_resume_connection (rc->connection); GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, @@ -275,7 +279,7 @@ handle_exchange_timeout (void *cls) TMH_EXCHANGES_find_exchange_cancel (rc->fo); rc->fo = NULL; } - rc->suspended = false; + rc->suspended = GNUNET_NO; MHD_resume_connection (rc->connection); GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, @@ -334,15 +338,17 @@ TMH_private_post_reserves (const struct TMH_RequestHandler *rh, = GNUNET_SCHEDULER_add_delayed (EXCHANGE_GENERIC_TIMEOUT, &handle_exchange_timeout, rc); - rc->suspended = true; + rc->suspended = GNUNET_YES; GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); MHD_suspend_connection (connection); return MHD_YES; } + if (GNUNET_SYSERR == rc->suspended) + return MHD_NO; /* we are in shutdown */ - GNUNET_assert (! rc->suspended); + GNUNET_assert (GNUNET_NO == rc->suspended); if (NULL == rc->payto_uri) { return TALER_MHD_reply_with_error (connection, diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c b/src/backend/taler-merchant-httpd_private-post-transfers.c index f06f25c0..b6745c55 100644 --- a/src/backend/taler-merchant-httpd_private-post-transfers.c +++ b/src/backend/taler-merchant-httpd_private-post-transfers.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2021 Taler Systems SA + (C) 2014-2022 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 published by the Free Software @@ -138,6 +138,15 @@ struct PostTransfersContext enum GNUNET_GenericReturnValue check_transfer_result; /** + * Did we suspend @a connection and are thus in + * the #ptc_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. + */ + enum GNUNET_GenericReturnValue suspended; + + /** * Should we retry the transaction due to a serialization error? */ bool soft_retry; @@ -147,10 +156,6 @@ struct PostTransfersContext */ bool downloaded; - /** - * Are we currently suspended? - */ - bool suspended; }; @@ -175,7 +180,7 @@ TMH_force_post_transfers_resume () GNUNET_CONTAINER_DLL_remove (ptc_head, ptc_tail, ptc); - ptc->suspended = false; + ptc->suspended = GNUNET_SYSERR; MHD_resume_connection (ptc->connection); if (NULL != ptc->timeout_task) { @@ -213,7 +218,7 @@ resume_transfer_with_response (struct PostTransfersContext *ptc, GNUNET_CONTAINER_DLL_remove (ptc_head, ptc_tail, ptc); - ptc->suspended = false; + ptc->suspended = GNUNET_NO; MHD_resume_connection (ptc->connection); TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ } @@ -891,7 +896,7 @@ download (struct PostTransfersContext *ptc) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suspending POST /private/transfers handling while working with exchange\n"); MHD_suspend_connection (ptc->connection); - ptc->suspended = true; + ptc->suspended = GNUNET_YES; GNUNET_CONTAINER_DLL_insert (ptc_head, ptc_tail, ptc); @@ -923,6 +928,8 @@ TMH_private_post_transfers (const struct TMH_RequestHandler *rh, hc->ctx = ptc; hc->cc = &transfer_cleanup; } + if (GNUNET_SYSERR == ptc->suspended) + return MHD_NO; /* we are in shutdown */ /* resume logic: did we get resumed after a reply was built? */ if (0 != ptc->response_code) return queue (ptc); @@ -930,7 +937,7 @@ TMH_private_post_transfers (const struct TMH_RequestHandler *rh, (NULL != ptc->wdh) ) { /* likely old MHD version causing spurious wake-up */ - GNUNET_break (ptc->suspended); + GNUNET_break (GNUNET_NO == ptc->suspended); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sure why we are here, should be suspended\n"); return MHD_YES; /* still work in progress */ |