statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.69k stars 508 forks source link

Static cache error – Undefined array key "scheme" #6764

Closed ellimondo closed 1 year ago

ellimondo commented 1 year ago

Bug description

When saving a collection entry – specifically static entries in this case - I suddenly get a server error.

How to reproduce

The entry is actually saved but the static cache is not cleared and an error is thrown.

This occurred once statamic cms is updated to 3.3.36. I also updated to 3.3.37 to see if there was a fix but the error remains.

I've gone back locally to 3.3.35, run statamic update, pushed the changes, and the error goes away.

Log error listed below.

Logs

[2022-09-22 10:37:50] production.ERROR: Undefined array key "scheme" {"userId":"8c7177e2-ca46-4c53-b469-f05d5efa5fad","exception":"[object] (ErrorException(code: 0): Undefined array key \"scheme\" at /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/Cachers/AbstractCacher.php:295)
[stacktrace]
#0 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/Cachers/AbstractCacher.php(295): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/Cachers/AbstractCacher.php(229): Statamic\\StaticCaching\\Cachers\\AbstractCacher->getPathAndDomain()
#2 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/Cachers/AbstractCacher.php(248): Statamic\\StaticCaching\\Cachers\\AbstractCacher->invalidateWildcardUrl()
#3 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(245): Statamic\\StaticCaching\\Cachers\\AbstractCacher->Statamic\\StaticCaching\\Cachers\\{closure}()
#4 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/Cachers/AbstractCacher.php(252): Illuminate\\Support\\Collection->each()
#5 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/DefaultInvalidator.php(71): Statamic\\StaticCaching\\Cachers\\AbstractCacher->invalidateUrls()
#6 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/DefaultInvalidator.php(32): Statamic\\StaticCaching\\DefaultInvalidator->invalidateEntryUrls()
#7 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/StaticCaching/Invalidate.php(70): Statamic\\StaticCaching\\DefaultInvalidator->invalidate()
#8 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Events/CallQueuedListener.php(107): Statamic\\StaticCaching\\Invalidate->invalidateEntry()
#9 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Events\\CallQueuedListener->handle()
#10 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#11 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#12 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#13 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#14 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\\Container\\Container->call()
#15 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}()
#16 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#17 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\\Pipeline\\Pipeline->then()
#18 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(120): Illuminate\\Bus\\Dispatcher->dispatchNow()
#19 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Queue\\CallQueuedHandler->Illuminate\\Queue\\{closure}()
#20 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#21 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\\Pipeline\\Pipeline->then()
#22 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\\Queue\\CallQueuedHandler->dispatchThroughMiddleware()
#23 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\\Queue\\CallQueuedHandler->call()
#24 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(43): Illuminate\\Queue\\Jobs\\Job->fire()
#25 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Queue/Queue.php(57): Illuminate\\Queue\\SyncQueue->push()
#26 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(574): Illuminate\\Queue\\Queue->pushOn()
#27 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(498): Illuminate\\Events\\Dispatcher->queueHandler()
#28 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(424): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}()
#29 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(249): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}()
#30 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(450): Illuminate\\Events\\Dispatcher->dispatch()
#31 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Events/Dispatchable.php(14): event()
#32 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Entries/Entry.php(332): Statamic\\Events\\Event::dispatch()
#33 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Controllers/CP/Collections/EntriesController.php(240): Statamic\\Entries\\Entry->save()
#34 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Statamic\\Http\\Controllers\\CP\\Collections\\EntriesController->update()
#35 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction()
#36 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Route.php(262): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#37 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\\Routing\\Route->runController()
#38 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\\Routing\\Route->run()
#39 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#40 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CP/CountUsers.php(18): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#41 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CP\\CountUsers->handle()
#42 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CP/Localize.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#43 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CP\\Localize->handle()
#44 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CP/Authorize.php(25): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#45 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CP\\Authorize->handle()
#46 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CP/AddToasts.php(22): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#47 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CP\\AddToasts->handle()
#48 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CP/AuthGuard.php(14): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#49 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CP\\AuthGuard->handle()
#50 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CP/ContactOutpost.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#51 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CP\\ContactOutpost->handle()
#52 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#53 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#54 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#55 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#56 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#58 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#60 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Session\\Middleware\\StartSession->handle()
#61 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#62 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#63 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#64 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#65 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/SwapExceptionHandler.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#66 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\SwapExceptionHandler->handle()
#67 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#68 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(723): Illuminate\\Pipeline\\Pipeline->then()
#69 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(698): Illuminate\\Routing\\Router->runRouteWithinStack()
#70 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\\Routing\\Router->runRoute()
#71 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\\Routing\\Router->dispatchToRoute()
#72 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\\Routing\\Router->dispatch()
#73 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#74 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/DisableFloc.php(18): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#75 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\DisableFloc->handle()
#76 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CheckMultisite.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#77 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CheckMultisite->handle()
#78 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/CheckComposerJsonScripts.php(14): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#79 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\CheckComposerJsonScripts->handle()
#80 /home/forge/north-v-south.co.uk/vendor/statamic/cms/src/Http/Middleware/PoweredByHeader.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#81 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Statamic\\Http\\Middleware\\PoweredByHeader->handle()
#82 /home/forge/north-v-south.co.uk/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#83 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#84 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#85 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#86 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#87 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#88 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#89 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#90 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#91 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#92 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#93 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#94 /home/forge/north-v-south.co.uk/vendor/fruitcake/laravel-cors/src/HandleCors.php(38): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#95 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\\Cors\\HandleCors->handle()
#96 /home/forge/north-v-south.co.uk/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#97 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\\Proxy\\TrustProxies->handle()
#98 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#99 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\\Pipeline\\Pipeline->then()
#100 /home/forge/north-v-south.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#101 /home/forge/north-v-south.co.uk/public/index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle()
#102 {main}
"}

Environment

Statamic 3.3.37 Solo
Laravel 8.83.23
PHP 8.0.15
doublethreedigital/duplicator 2.3.2
rias/statamic-data-import 1.2.2
statamic/podcast-categories 1.0.1
statamic/ssg 1.2.0

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

No response

lakkes-ra commented 1 year ago

Can confirm the bug. Same thing recently crashed a customer website.

jasonvarga commented 1 year ago

Can you both please provide your config/statamic/sites.php and config/statamic/static_caching.php files?

lakkes-ra commented 1 year ago

Sure:

sites.php

return [

    'sites' => [

        'default' => [
            'name' => 'Deutsch',
            'locale' => 'de_DE',
            'url' => '/',
            'attributes' => [
                'site_name' => config('app.name'),
                'lang_switcher_hint' => 'Seite auf Deutsch ansehen'
            ]
        ],

        'english' => [
            'name' => 'English',
            'locale' => 'en_GB',
            'url' => '/en/',
            'attributes' => [
                'site_name' => config('app.name'),
                'lang_switcher_hint' => 'Go to English site'
            ]
        ],

    ],
];

static_caching.php

return [

    'strategy' => env('STATAMIC_STATIC_CACHING_STRATEGY', null),

    'strategies' => [

        'half' => [
            'driver' => 'application',
            'expiry' => null,
        ],

        'full' => [
            'driver' => 'file',
            'path' => public_path('static'),
            'lock_hold_length' => 0,
        ],

    ],

    'exclude' => [
        '/sitemap.xml',
        '/livewire*',
    ],

    'invalidation' => [

        'class' => null,

        'rules' => 'all',

    ],

    'ignore_query_strings' => false,

];
arthurperton commented 1 year ago

Related to #6496?

ellimondo commented 1 year ago

Here’s mine:

sites.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Sites
    |--------------------------------------------------------------------------
    |
    | Each site should have root URL that is either relative or absolute. Sites
    | are typically used for localization (eg. English/French) but may also
    | be used for related content (eg. different franchise locations).
    |
    */

    'sites' => [

        'default' => [
            'name' => config('app.name'),
            'locale' => 'en_US',
            'url' => '/',
        ],

    ],
];

static_caching.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Active Static Caching Strategy
    |--------------------------------------------------------------------------
    |
    | To enable Static Caching, you should choose a strategy from the ones
    | you have defined below. Leave this null to disable static caching.
    |
    */

    'strategy' => 'full',

    /*
    |--------------------------------------------------------------------------
    | Caching Strategies
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the static caching strategies for your
    | application as well as their drivers.
    |
    | Supported drivers: "application", "file"
    |
    */

    'strategies' => [

        'half' => [
            'driver' => 'application',
            'expiry' => null,
        ],

        'full' => [
            'driver' => 'file',
            'path' => public_path('static'),
            'lock_hold_length' => 0,
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Exclusions
    |--------------------------------------------------------------------------
    |
    | Here you may define a list of URLs to be excluded from static
    | caching. You may want to exclude URLs containing dynamic
    | elements like contact forms, or shopping carts.
    |
    */

    'exclude' => [
            '/feed.xml'
    ],

    /*
    |--------------------------------------------------------------------------
    | Invalidation Rules
    |--------------------------------------------------------------------------
    |
    | Here you may define the rules that trigger when and how content would be
    | flushed from the static cache. See the documentation for more details.
    | If a custom class is not defined, the default invalidator is used.
    |
    | https://statamic.dev/static-caching
    |
    */

    'invalidation' => [

        'rules' => [
        'collections' => [
            'episodes' => [
                'urls' => [
                    '/episodes*',
                    '/episodes/*',
                    '/',
                    '*',
                ]
            ],
            'pies' => [
                'urls' => [
                    '/pie-charts*',
                    '/episodes*',
                ]
            ]
        ]   
        ]

    ],

    /*
    |--------------------------------------------------------------------------
    | Ignoring Query Strings
    |--------------------------------------------------------------------------
    |
    | Statamic will cache pages of the same URL but with different query
    | parameters separately. This is useful for pages with pagination.
    | If you'd like to ignore the query strings, you may do so.
    |
    */

    'ignore_query_strings' => true,

];
jasonvarga commented 1 year ago

To both of you, I think this could be worked around by using an actual url in your site config.

        'default' => [
            'name' => config('app.name'),
            'locale' => 'en_US',
            'url' => '/',
        ],

Change '/' to 'https://yoursite.com/ or use an environment variable like env('APP_URL').

We'll look into the actual issue, but this could solve your error for now.

ellimondo commented 1 year ago

Hi Jason

I'd already tried the first example - I tried the env variable as well - but the error persists - this is on 3.3.37 locally.

jasonvarga commented 1 year ago

How are you serving your sites? Laravel Valet?

I can't reproduce this. Would you be able to provide a github repo with this problem happening?

lakkes-ra commented 1 year ago

Hej Jason, we tried the workaround fix, but it didn't work, either.

We actually rolled back to v3.3.35 and the error still persists. The site where the error occurs is served with k8s on a live server and it occurs only when we turn on static caching (half). With stataic caching turned off, the page works.

The error we have is not the same as above, but it has the same pattern.

production.ERROR: Undefined array key "b78dd0dbcef234639b15d6854a7bfa39980cda7a" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"b78dd0dbcef234639b15d6854a7bfa39980cda7a\" at /home/forge/alaskapac.org/vendor/laravel/framework/src/Illuminate/Collections/Collection.php:1679)

Sound like it is somehow related to https://github.com/statamic/cms/issues/6781 and https://github.com/statamic/cms/issues/6496

We couldn't reproduce it locally, either.

jasonvarga commented 1 year ago

Are you load balancing? What cache driver are you using?

ChrisWorkhouse commented 1 year ago

I'm also having this issue for one of our sites with the static cache strategy set to half and using the file cache driver.

No load balancing or anything. Just a straight LAMP stack.

ChrisWorkhouse commented 1 year ago

The above was on my staging server. I've also reproduced it on a local dev copy

image

Environment
Application Name: Statamic
Laravel Version: 9.34.0
PHP Version: 8.0.7
Composer Version: 2.1.9
Environment: local
Debug Mode: ENABLED
URL: peldon.test/
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log`
Cache: statamic
Database: mysql
Logs: stack
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 2
Antlers: runtime
Version: 3.3.43 PRO

Statamic Addons
rias/statamic-address-field: 1.0.3
statamic/seo-pro: 3.1.0
ChrisWorkhouse commented 1 year ago

I believe I've found the source of the issue described above (at least on my project), and it comes down to the invalidation rules.

I found if a URL in the invalidation rule does not start with a '/' then you get the above error when saving that collection / taxonomy term / etc.

For example, the below rules triggers the error when saving:

'rules' => [
    'collections' => [
        'news' => [
            'urls' => [
                'news'
            ]
        ],
        'projects' => [
            'urls' => [
                'projects',
                'projects/inspiration',
                'projects/map',
            ]
        ],
        'people' => [
            'urls' => [
                'about/people'
            ]
        ],
        'jobs' => [
            'urls' => [
                'about/jobs'
            ]
        ],
    ],
],

And changing to this resolves the error:

'rules' => [
    'collections' => [
        'news' => [
            'urls' => [
                '/news'
            ]
        ],
        'projects' => [
            'urls' => [
                '/projects',
                '/projects/inspiration',
                '/projects/map',
            ]
        ],
        'people' => [
            'urls' => [
                '/about/people'
            ]
        ],
        'jobs' => [
            'urls' => [
                '/about/jobs'
            ]
        ],
    ],
],

Without diving deeper in to how Statamic static caching works under the hood, I assume it may be using the PHP function parse_url which is failing when the rules don't include the prefixed slash.

I hope this helps!

ellimondo commented 1 year ago

I can confirm that works with 3.3.43. I'd tried the trailing slash before but had overlooked putting one before a catchall *.

Great spot Chris thanks.

Jon

cwyrwas commented 1 year ago

Thank you @ChrisWorkhouse! That fixed it for me.

Can we add some sort of check to prepend a slash if it's not present? It looks like that happens in /cms/src/StaticCaching/Cachers/AbstractCacher.php

In the getPathAndDomain method, it uses parse_url.

Here's the current code:

protected function getPathAndDomain($url)
    {
        if (Str::startsWith($url, '/')) {
            return [
                $url,
                $this->getBaseUrl(),
            ];
        }

        $parsed = parse_url($url);

        $query = isset($parsed['query']) ? '?'.$parsed['query'] : '';

        $path = $parsed['path'] ?? '/';

        return [
            $path.$query,
            $parsed['scheme'].'://'.$parsed['host'],
        ];
    }

I think adding something like the below code could be a preventative measure, but I'm not entirely familiar with everything going on in terms of the caching system. This effectively just checks the first character of the string of the path for a '/', and it prepends it to the string if it's not present. I'm not sure how elegant of a solution that is, but maybe it's worth looking into.

protected function getPathAndDomain($url)
    {
        if (Str::startsWith($url, '/')) {
            return [
                $url,
                $this->getBaseUrl(),
            ];
        }

        $parsed = parse_url($url);

        $query = isset($parsed['query']) ? '?'.$parsed['query'] : '';

        if (!$parsed['path']) {
            $path = '/';
        } else {
             if (substr($parsed['path'],0,1) != '/') {
                $path = '/' . $parsed['path'];
             }
        }

        return [
            $path.$query,
            $parsed['scheme'].'://'.$parsed['host'],
        ];
    }
ben182 commented 1 year ago

Still happening in Version: 3.3.58, slash already in place

arthurperton commented 1 year ago

Nice work tracking down the issue @ChrisWorkhouse 💪🏻 !