clockwork icon indicating copy to clipboard operation
clockwork copied to clipboard

Seems to break Laravel even with APP_DEBUG false when index file is not writeable

Open joelharkes opened this issue 4 years ago • 19 comments

first I got a laravel translator error because the translator class could not be loaded necessary for the 500 error blade page. the real error behind it is:

ocal.ERROR: unhandled exception. {"exceptionMessage":"Path \"/var/www/html/storage/clockwork/index\" is not writable.","stack":"#0 /var/www/html/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel
/ClockworkSupport.php(216): Clockwork\\Storage\\FileStorage->__construct()
php       | #1 /var/www/html/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkServiceProvider.php(82): Clockwork\\Support\\Laravel\\ClockworkSupport->makeStorage()
php       | #2 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(826): Clockwork\\Support\\Laravel\\ClockworkServiceProvider->Clockwork\\Support\\Laravel\\{closure}()
php       | #3 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(712): Illuminate\\Container\\Container->build()
php       | #4 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\\Container\\Container->resolve()
php       | #5 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\\Foundation\\Application->resolve()
php       | #6 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(781): Illuminate\\Container\\Container->make()
php       | #7 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(1354): Illuminate\\Foundation\\Application->make()
php       | #8 /var/www/html/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkServiceProvider.php(70): Illuminate\\Container\\Container->offsetGet()
php       | #9 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(826): Clockwork\\Support\\Laravel\\ClockworkServiceProvider->Clockwork\\Support\\Laravel\\{closure}()
php       | #10 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(712): Illuminate\\Container\\Container->build()
php       | #11 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\\Container\\Container->resolve()
php       | #12 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\\Foundation\\Application->resolve()
php       | #13 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(781): Illuminate\\Container\\Container->make()
php       | #14 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(1354): Illuminate\\Foundation\\Application->make()
php       | #15 /var/www/html/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkSupport.php(448): Illuminate\\Container\\Container->offsetGet()
php       | #16 /var/www/html/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkServiceProvider.php(48): Clockwork\\Support\\Laravel\\ClockworkSupport->configureShouldCollect()
php       | #17 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(627): Clockwork\\Support\\Laravel\\ClockworkServiceProvider->register()
php       | #18 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(75): Illuminate\\Foundation\\Application->register()
php       | #19 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(604): Illuminate\\Foundation\\ProviderRepository->load()
php       | #20 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\\Foundation\\Application->registerConfiguredProviders()
php       | #21 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(230): Illuminate\\Foundation\\Bootstrap\\RegisterProviders->bootstrap()
php       | #22 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(152): Illuminate\\Foundation\\Application->bootstrapWith()
php       | #23 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(136): Illuminate\\Foundation\\Http\\Kernel->bootstrap()
php       | #24 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
php       | #25 /var/www/html/public/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle()
php       | #26 {main}","exCode":0}

i would expect actually if clock work is disabled all this stuff wouldn't happen either?

here is where it tries to read/write the index file. maybe this couldnt shouldnt happen already?

public function configureShouldCollect()
	{
		$this->app['clockwork']
}

Solution

adding

if (! $this->app['clockwork.support']->isEnabled()) return;

before:

$this->app->make('clockwork.request'); // instantiate the request to have id and time available as early as possible

joelharkes avatar Nov 25 '20 16:11 joelharkes

Hey, I agree this is a bit of an unexpected behavior. Not sure about the solution yet, will need to investigate more.

itsgoingd avatar Dec 01 '20 23:12 itsgoingd

The solution I'm using to ensure Clockwork isn't loaded outside of local is similar to the local only installation of Telescope

AppServiceProvider:

public function register()
{
    if ($this->app->environment('local') && config('clockwork.enable')) {
        $this->app->register(\Clockwork\Support\Laravel\ClockworkServiceProvider::class);
    }
}

composer.json:

"extra": {
    "laravel": {
        "dont-discover": [
            "itsgoingd/clockwork"
        ]
    }
},

petecoop avatar Jan 13 '21 18:01 petecoop

@itsgoingd Should we use @petecoop approach to avoid this?

Sergiobop avatar May 19 '21 13:05 Sergiobop

I see no issues with the conditional registration approach described above. This will also be resolved at the Clockwork side at some point.

itsgoingd avatar May 22 '21 14:05 itsgoingd

The solution I'm using to ensure Clockwork isn't loaded outside of local is similar to the local only installation of Telescope

AppServiceProvider:

public function register()
{
    if ($this->app->environment('local') && config('clockwork.enable')) {
        $this->app->register(\Clockwork\Support\Laravel\ClockworkServiceProvider::class);
    }
}

composer.json:

"extra": {
    "laravel": {
        "dont-discover": [
            "itsgoingd/clockwork"
        ]
    }
},

Maybe I've misunderstood something, but would installing Clockwork as a dev dependency and removing it in production with composer --no-dev solve this issue?

hashimaziz1 avatar Mar 27 '22 01:03 hashimaziz1

Sure, installing as a dev dependency is also a good workaround, will think about recommending that in the future.

itsgoingd avatar Mar 27 '22 20:03 itsgoingd

Sure, installing as a dev dependency is also a good workaround, will think about recommending that in the future.

But what I'm really interested is whether this is a solution to the problem at all. I'm running into the same 500 error - /storage/clockwork/index\ is not writable, and maybe I'm misunderstanding Clockwork - but isn't part of its design to run on the server itself? I've seen it described in places as a server-side tool to analyse sites in production. Even the documentation for this very repository says it:

contains the server-side component of Clockwork

If this is the case then either disabling it in non-local environments isn't a solution at all, or I'm misunderstanding something.

hashimaziz1 avatar Mar 28 '22 17:03 hashimaziz1

Maybe I've misunderstood something, but would installing Clockwork as a dev dependency and removing it in production with composer --no-dev solve this issue?

In production yes. In our case issue was with staging environment, where we kind of needed dev dependencies for testing related stuff. So the AppServiceProvider workaround helped.

If this is the case then either disabling it in non-local environments isn't a solution at all, or I'm misunderstanding something.

For some teams this is the solution, for some it's not (worked for us). By the way, we didn't have that issue until we upgraded to v5.1.5. Old version was v.4.1.7 IIRC. Behaviour has changed somewhere in between. I believe Clockwork simply should not try to create index file if it's disabled in config. No matter environment and/or debug mode.

frutality avatar Mar 30 '22 09:03 frutality

The solution I'm using to ensure Clockwork isn't loaded outside of local is similar to the local only installation of Telescope

AppServiceProvider:

public function register()
{
    if ($this->app->environment('local') && config('clockwork.enable')) {
        $this->app->register(\Clockwork\Support\Laravel\ClockworkServiceProvider::class);
    }
}

composer.json:

"extra": {
    "laravel": {
        "dont-discover": [
            "itsgoingd/clockwork"
        ]
    }
},

I'm experiencing the same issue and for some reason this solution does not work in our situation. Anybody else has an updated solution? Maybe this could be added to the package to avoid writing the index file when clockwork should not be enabled?

tomvo avatar Aug 02 '22 09:08 tomvo

Hey, I would suggest explicitly disabling Clockwork by setting CLOCKWORK_ENABLE=false in your env file.

itsgoingd avatar Aug 02 '22 11:08 itsgoingd

I need to disabled clockwork in an specific script and then, enable it again!!

pablocasas74 avatar Nov 09 '22 13:11 pablocasas74

Even in disabled mode clockwork creates the temporary directories if used within laravel and this should not be the done. Running a test (which uses another user than the webserver), always gives me permission issues on the /tmp/clockwork-folder.

wietsewarendorff avatar Nov 29 '22 10:11 wietsewarendorff

To disable clockwork completely in laravel (and prevent permission-problems for instance), add this as a first line in the boot() and register() methods in the ClockworkServiceProvider:

if (!config('clockwork.enable', false)) return;

wietsewarendorff avatar Dec 30 '22 15:12 wietsewarendorff

Same issue v5.1

arturasfrontit avatar Jun 19 '23 07:06 arturasfrontit

also having this, can this be fixed @itsgoingd ?

mstaack avatar Nov 07 '23 11:11 mstaack

Hey, I've moved the path checks to the store method in dev-master, this should fix the issue.

itsgoingd avatar Nov 13 '23 20:11 itsgoingd

Hey, I've moved the path checks to the store method in dev-master, this should fix the issue.

Thanks @itsgoingd. Any chance of a minor release?

ababkov avatar Dec 18 '23 04:12 ababkov

I'm planning to tag a new release later this week.

itsgoingd avatar Dec 18 '23 10:12 itsgoingd

Same problem with disabled clockwork. Hope release will be soon.

beholdr avatar Jan 22 '24 16:01 beholdr

This behavior is finally changed in Clockwork 5.2, closing them 2020 issues, woo.

itsgoingd avatar Feb 21 '24 20:02 itsgoingd