Skip to content
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

unserialize(): Error at offset 10000 of 10000 bytes #173

Closed
foremtehan opened this issue Apr 11, 2021 · 4 comments
Closed

unserialize(): Error at offset 10000 of 10000 bytes #173

foremtehan opened this issue Apr 11, 2021 · 4 comments
Assignees
Labels

Comments

@foremtehan
Copy link
Contributor

foremtehan commented Apr 11, 2021

  • Octane Version: 0.1.1
  • Laravel Version: 8
  • PHP Version: 8
  • Server: Swoole

Description:

I just changed my default cache driver to octane and i got the following error:

unserialize(): Error at offset 10000 of 10000 bytes#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /app/vendor/laravel/octane/src/Cache/OctaneStore.php(37): unserialize()
#2 /app/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(97): Laravel\Octane\Cache\OctaneStore->get()
#3 /app/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(376): Illuminate\Cache\Repository->get()
#4 /app/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(392): Illuminate\Cache\Repository->remember()
#5 /app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Cache\CacheManager->__call()
#8 /app/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(234):
#13 [internal function]: Illuminate\Routing\RouteFileRegistrar->{closure}()
#14 /app/vendor/laravel/octane/src/Concerns/ProvidesRouting.php(53): call_user_func()
#15 /app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Laravel\Octane\Octane->invokeRoute()
#16 /app/vendor/laravel/octane/src/ApplicationGateway.php(33): Illuminate\Support\Facades\Facade::__callStatic()
#17 /app/vendor/laravel/octane/src/Worker.php(94): Laravel\Octane\ApplicationGateway->handle()
#18 /app/vendor/laravel/octane/bin/swoole-server(119): Laravel\Octane\Worker->handle()
#19 [internal function]: {closure}()
#20 /app/vendor/laravel/octane/bin/swoole-server(169): Swoole\Server->start()
#21 {main}

Looks like it have problem with Eloquent\Collection, if the data is big, it cannot cache it:

Cache::store('octane')->rememberForever('key', fn() => Thread::query()->latest()->take(100)->get());
@Namoshek
Copy link
Contributor

Namoshek commented Apr 11, 2021

The Octane cache is based on a Swoole Table, in case you are using the Swoole server. The cache is limited to 1000 rows with 10.000 bytes each by default:

octane/config/octane.php

Lines 125 to 139 in 9faedfb

/*
|--------------------------------------------------------------------------
| Octane Cache Table
|--------------------------------------------------------------------------
|
| While using Swoole, you may leverage the Octane cache, which is powered
| by a Swoole table. You may set the maximum number of rows as well as
| the number of bytes per row using the configuration options below.
|
*/
'cache' => [
'rows' => 1000,
'bytes' => 10000,
],

For larger items, you might want to:

  • consider using a different type of cache
  • increase the default size of the Octane cache per item
  • define and use a separate Swoole Table for the larger items

I suspect your initial exception occured because the data was truncated during insert.

@wimil
Copy link

wimil commented Dec 1, 2021

I have the same problem, how can I fix it ?, I tried to increase the bytes and row but it doesn't work.

@haught
Copy link

haught commented Dec 5, 2021

This is an issue that needs to be worked around. You can set an entry to the swoole table that is larger the it can contain and we don't get a false back from $this->table->set() in the put method. It thinks it added it correctly. This would probably be something that swoole needs to address.

The problem on the octane side is that we are failing to handle the unserialize error on the get method. The data is corrupted, it should be handled in some way. Report the error (maybe a more friendly message...) and return null as if the record was not found would seem like a logical workaround for the get method.

            try {
                return unserialize($record['value']);
            } catch (Throwable $e) {
                report($e);
                return null;
            }

@nunomaduro
Copy link
Member

This will be fixed on the next release, next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants