arthurperton / statamic-popular

Other
0 stars 0 forks source link

unserialize(): Error at offset 4948 of 4958 bytes #5

Closed SteveEdson closed 9 months ago

SteveEdson commented 11 months ago

Bug description

production.ERROR: unserialize(): Error at offset 4948 of 4958 bytes {"exception":"[object] (ErrorException(code: 0): unserialize(): Error at offset 4948 of 4958 bytes at /home/forge/site/vendor/arthurperton/popular/src/Pageviews/LockingFile.php:98)
Stacktrace

[2023-11-20 17:36:02] production.ERROR: unserialize(): Error at offset 4948 of 4958 bytes {"exception":"[object] (ErrorException(code: 0): unserialize(): Error at offset 4948 of 4958 bytes at /home/forge/site/vendor/arthurperton/popular/src/Pageviews/LockingFile.php:98)
[stacktrace]
#0 /home/forge/site/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(254): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /home/forge/site/vendor/arthurperton/popular/src/Pageviews/LockingFile.php(98): unserialize()
#3 /home/forge/site/vendor/arthurperton/popular/src/Pageviews/LockingFile.php(57): ArthurPerton\\Popular\\Pageviews\\LockingFile->readDataFromStream()
#4 /home/forge/site/vendor/arthurperton/popular/src/Pageviews/Repository.php(55): ArthurPerton\\Popular\\Pageviews\\LockingFile->modify()
#5 /home/forge/site/vendor/arthurperton/popular/src/Pageviews/Repository.php(30): ArthurPerton\\Popular\\Pageviews\\Repository->update()
#6 /home/forge/site/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(353): ArthurPerton\\Popular\\Pageviews\\Repository->addMultiple()
#7 /home/forge/site/vendor/arthurperton/popular/src/Pageviews/Aggregator.php(19): Illuminate\\Support\\Facades\\Facade::__callStatic()
#8 /home/forge/site/vendor/arthurperton/popular/src/Console/Commands/Aggregate.php(41): ArthurPerton\\Popular\\Pageviews\\Aggregator->aggregate()
#9 /home/forge/site/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): ArthurPerton\\Popular\\Console\\Commands\\Aggregate->handle()
#10 /home/forge/site/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#11 /home/forge/site/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#12 /home/forge/site/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#13 /home/forge/site/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call()
#14 /home/forge/site/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\\Container\\Container->call()
#15 /home/forge/site/vendor/symfony/console/Command/Command.php(326): Illuminate\\Console\\Command->execute()
#16 /home/forge/site/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Symfony\\Component\\Console\\Command\\Command->run()
#17 /home/forge/site/vendor/symfony/console/Application.php(1081): Illuminate\\Console\\Command->run()
#18 /home/forge/site/vendor/symfony/console/Application.php(320): Symfony\\Component\\Console\\Application->doRunCommand()
#19 /home/forge/site/vendor/symfony/console/Application.php(174): Symfony\\Component\\Console\\Application->doRun()
#20 /home/forge/site/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\\Component\\Console\\Application->run()
#21 /home/forge/site/artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle()
#22 {main}
"} 

How to Reproduce

Site has been running fine without issue, then suddenly this issue has occurred.

Expected behavior

A clear and concise description of what you expected to happen.

Extra Detail

If applicable, add screenshots, error messages etcetera to help explain your problem.

Environment

Environment Application Name: Statamic Laravel Version: 10.32.1 PHP Version: 8.2.11 Composer Version: 2.6.5 Environment: production Debug Mode: OFF URL: site.com Maintenance Mode: OFF

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

Drivers Broadcasting: log Cache: redis Database: mysql Logs: stack / single Mail: smtp Queue: redis Session: file

Statamic Addons: 3 Antlers: runtime Stache Watcher: Enabled Static Caching: half Version: 4.35.0 PRO

Statamic Addons arthurperton/popular: 1.1.0 pecotamic/sitemap: 1.4.6 statamic/ssg: 2.2.0

Install method for Statamic (choose one):

Fresh install from statamic/statamic

SteveEdson commented 11 months ago

After a bit more digging, it looks like it's caused by the penetration test which was ran against the website. It appears to have logged the pageviews for the random test pages, and cannot be unserialised as a result.

Ideally, it would only add entries to the pageviews file if they exist within statamic. I can share this file with you if it helps.

arthurperton commented 11 months ago

Thanks for your report!

From the looks of it, your file containing the collected pageviews got corrupted. The file can be found in storage\popular\pageviews so if you are using version control, you could restore a version of the file from before it got corrupted.

Also, as a workaround, you can temporarily disable the pageview tracking during the penetration test by setting POPULAR_TRACKER_ENABLED=false in your .env file

As for the cause, I am not sure how the file got corrupted in your case, it might indeed help if you share the pageviews file.

arthurperton commented 9 months ago

I hope you were able to restore or recreate your file using the instructions above. I am closing the issue now, please feel free to reopen it if it occurs again.