clockwork icon indicating copy to clipboard operation
clockwork copied to clipboard

fclose(): supplied resource is not a valid stream resource

Open flexchar opened this issue 3 years ago • 1 comments

PHP 8.1.8 Laravel Framework 9.21.4 Clockwork v5.1.6 Laravel Octane v1.2.16

I noticed I'm Clockwork is not working and I'm getting ton of errors in the output. Public Sentry link here: https://sentry.io/share/issue/54f1635aeb7944eca679938690e31bbf/

In the browser console I can see that request to /__clockwork/latest is failing with 500.

Text dump:

[2022-08-01 08:31:38] staging.ERROR: fclose(): supplied resource is not a valid stream resource {"exception":"[object] (TypeError(code: 0): fclose(): supplied resource is not a valid stream resource at /var/www/vendor/itsgoingd/clockwork/Clockwork/Storage/FileStorage.php:199)
[stacktrace]
#0 /var/www/vendor/itsgoingd/clockwork/Clockwork/Storage/FileStorage.php(199): fclose(Resource id #1014)
#1 /var/www/vendor/itsgoingd/clockwork/Clockwork/Storage/FileStorage.php(186): Clockwork\\Storage\\FileStorage->closeIndex()
#2 /var/www/vendor/itsgoingd/clockwork/Clockwork/Storage/FileStorage.php(107): Clockwork\\Storage\\FileStorage->openIndex('start', true, true)
#3 /var/www/vendor/itsgoingd/clockwork/Clockwork/Storage/FileStorage.php(93): Clockwork\\Storage\\FileStorage->cleanup()
#4 /var/www/vendor/itsgoingd/clockwork/Clockwork/Clockwork.php(133): Clockwork\\Storage\\FileStorage->store(Object(Clockwork\\Request\\Request))
#5 /var/www/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkSupport.php(446): Clockwork\\Clockwork->storeRequest()
#6 /var/www/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkMiddleware.php(36): Clockwork\\Support\\Laravel\\ClockworkSupport->recordRequest()
#7 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(209): Clockwork\\Support\\Laravel\\ClockworkMiddleware->terminate(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\Response))
#8 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(180): Illuminate\\Foundation\\Http\\Kernel->terminateMiddleware(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\Response))
#9 /var/www/vendor/laravel/octane/src/ApplicationGateway.php(50): Illuminate\\Foundation\\Http\\Kernel->terminate(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\Response))
#10 /var/www/vendor/laravel/octane/src/Worker.php(110): Laravel\\Octane\\ApplicationGateway->terminate(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\Response))
#11 /var/www/vendor/laravel/octane/bin/swoole-server(118): Laravel\\Octane\\Worker->handle(Object(Illuminate\\Http\\Request), Object(Laravel\\Octane\\RequestContext))
#12 [internal function]: {closure}(Object(Swoole\\Http\\Request), Object(Swoole\\Http\\Response))
#13 /var/www/vendor/laravel/octane/bin/swoole-server(164): Swoole\\Server->start()
#14 {main}
"}

Will attempt to switch sqlite driver to see if it changes anything.

Btw, this package is mind-blowing amazing! A big thank you!

flexchar avatar Aug 01 '22 08:08 flexchar

Hey, thanks for the report and the nice words. This should be fixed in master and will be released later this week.

The issue was caused by the old index file handle not being unset after closing it. This is normally not an issue, since the environment is thrown away after every request, but when running with Octane the environment gets reused, so we need to be more aware of what state we leave things in.

itsgoingd avatar Aug 04 '22 21:08 itsgoingd

Fixed in Clockwork 5.1.7.

itsgoingd avatar Aug 14 '22 21:08 itsgoingd

Thanks a ton!

flexchar avatar Aug 15 '22 15:08 flexchar