From dd5542ceea93e9153eaaa674b61b0d430e1e6f03 Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Fri, 23 Dec 2016 10:51:46 -0500 Subject: [PATCH] added usleep to prevent race condition this is relatively safe to do, even if 1000 memberships are created all at once, upon occasion. --- memberdashboard.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/memberdashboard.php b/memberdashboard.php index 34bcddf..202b62e 100644 --- a/memberdashboard.php +++ b/memberdashboard.php @@ -125,6 +125,14 @@ function memberdashboard_civicrm_post($op, $objectName, $objectId, &$objectRef) // TODO: Extract all of this to a class for clarity and // organization's sake. + // sleep for a half second in order to avoid a race condition preventing badge creation. + // This is somewhat sketchy, as this will tie up an apache processes, allowing for a DoS by someone + // creating many phony memberships in a short period of time. + // In practice, this isn't so bad. apache is currently configured to use prefork mpm on crmserver1p + // and has about 40 forked processes. so 800 new memberships all at once would tie up the server for + // an additional 10 seconds. + usleep(500000); + // Get the oldest join date for the contact's memberships. $contactId = $objectRef->contact_id; $dao = CRM_Core_DAO::executeQuery( -- 2.25.1