Problem/Motivation
Whenever Recurly sends a webhook we return an HtmlResponse(). This can result in an error like the following if your configuration uses tokens that that require rendering to populate fields in Drupal based on data received from Recurly.
Example error:
LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early.
This is related to this change: https://www.drupal.org/node/2513810
What happens is \Drupal\recurly\RecurlyEntityOperations::entityUpdate gets called, and depending on configuration, calls \Drupal::token()->replace() ... which can cause "early rendering".
It seems that one solution is to return a Symfony\Component\HttpFoundation\Response instead of a Drupal\Core\Render\HtmlResponse. Which in this case should be fine because we're just returning some basic text, and a status code, and don't need to actually respond with valid HTML.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork recurly-3360519
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
eojthebraveThis MR fixes the issues by converting all the responses returned from \Drupal\recurly\Controller\RecurlyPushListenerController::processPushNotification to use Symfony\Component\HttpFoundation\Response objects. Effectively this will change the response content from HTML to plain text. And bypasses core's early rendering safe guards. Since this page is really only intended for internal processing and to serve HTTP status codes to Recurly this shouldn't break anything.
I also updated one brittle test. The calculation performed in recurly_subscription_calculate_refund() depends on \Drupal::time()->getRequestTime() and as a result the output can vary slightly which causes intermittent test failures.
Comment #4
blakehall commentedThis looks good to me. And I'd love to get my logs cleaned up. Enthusiastic +1.
Comment #6
eojthebrave