New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta refresh is being output for API endpoints #1824

Closed
jackwakefield opened this Issue Mar 7, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@jackwakefield

jackwakefield commented Mar 7, 2018

Expected behaviour

The API request is blocked until the Stache has been warmed up.

Actual behaviour

The response was along the lines of <meta http-equiv="refresh" content="1; URL=..." />

Steps to reproduce

  1. Perform an API request while the Stache is being warmed up (I know, not great)

Server Details

Operating System: CentOS 7

Web Server: nginx

PHP Version: 7.2

Statamic Version: 2.8.7

Updated from an older Statamic or fresh install: Updated

List of installed addons: Mostly custom

@jackwakefield

This comment has been minimized.

jackwakefield commented Mar 7, 2018

Very crude proof of concept which blocks the request for up to 10 seconds while the Stache is being warmed up by another request, either outputting the meta tag after waiting 10 seconds (not ideal), or carrying on the request.

diff --git a/statamic/core/Providers/StacheServiceProvider.php b/statamic/core/Providers/StacheServiceProvider.php
index c6ed025..1fabc34 100644
--- a/statamic/core/Providers/StacheServiceProvider.php
+++ b/statamic/core/Providers/StacheServiceProvider.php
@@ -100,8 +100,14 @@ class StacheServiceProvider extends ServiceProvider
 
         $this->app->make(Stache::class)->locales(Config::getLocales());
 
-        if ($this->stache->isPerformingInitialWarmUp() && !app()->runningInConsole()) {
-            $this->outputRefreshResponse();
+        $startTime = time();
+
+        while ($this->stache->isPerformingInitialWarmUp() && !app()->runningInConsole()) {
+            if (time() - $startTime >= 10) {
+                $this->outputRefreshResponse();
+            }
+
+            usleep(1000);
         }
 
         $this->manager = $this->app->make(Manager::class);
@netnakgraham

This comment has been minimized.

netnakgraham commented Mar 15, 2018

I have Snipcart firing webhooks to my addon, this routinely "soft" fails because it gets a 200 from the refresh page, but the request never hits my addon controller.

I was thinking along the lines of detecting API requests and issuing a 503 so external services could retry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment