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

Argument 1 passed to phpFastCache\Core\DriverAbstract::driverUnwrapTime() must be of the type array, boolean given #330

Closed
ghost opened this issue Jul 25, 2016 · 20 comments

Comments

@ghost
Copy link

ghost commented Jul 25, 2016

This just rarely happens but it is still a bug

Argument 1 passed to phpFastCache\Core\DriverAbstract::driverUnwrapTime() must be of the type array, boolean given, called in /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php on line 122
File: /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Cache/DriverBaseTrait.php 


Trace:

#0 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php(122): phpFastCache\Core\DriverAbstract->driverUnwrapTime(false)
#1 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php(55): phpFastCache\Drivers\Files\Driver->driverRead(Object(phpFastCache\Drivers\Files\Item))
#2 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php(62): phpFastCache\Core\DriverAbstract->getItem('_TAG_friends.co...')
#3 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php(122): phpFastCache\Core\DriverAbstract->getItemsByTag('friends.count')
#4 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php(144): phpFastCache\Core\DriverAbstract->deleteItemsByTag('friends.count')
#5 /somepath/ow_plugins/ext/classes/backend_phpfastcache.php(54): phpFastCache\Core\DriverAbstract->deleteItemsByTags(Array)
.........................................................

My guess :

in \phpfastcache\phpfastcache\src\phpFastCache\Drivers\Files\Driver.php

$object = $this->decode($content);

not always return array.

Can I make a fix like this : adding !is_array($object) ||

  if (!is_array($object) || $this->driverUnwrapTime($object)->getTimestamp() < time()) {
        @unlink($file_path);

        return null;
    }
@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

I'll check it out. What's your Os/driver used?
Thanks you.

Le 25 juil. 2016 15:00, "phuyem" notifications@github.com a écrit :

This just rarely happens but it is still a bug

`Argument 1 passed to phpFastCache\Core\DriverAbstract::driverUnwrapTime()
must be of the type array, boolean given, called in
/somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php
on line 122
File:
/somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Cache/DriverBaseTrait.php

Trace:

#0
/somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php(122):
phpFastCache\Core\DriverAbstract->driverUnwrapTime(false)
#1 #1
/somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php(55):
phpFastCache\Drivers\Files\Driver->driverRead(Object(phpFastCache\Drivers\Files\Item))
#2 #2
/somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php(62):
phpFastCache\Core\DriverAbstract->getItem('_TAG_friends.co...')
#3 #3
/somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php(122):
phpFastCache\Core\DriverAbstract->getItemsByTag('friends.count')
#4 #4
/somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php(144):
phpFastCache\Core\DriverAbstract->deleteItemsByTag('friends.count')
#5 #5
/somepath/ow_plugins/ext/classes/backend_phpfastcache.php(54):
phpFastCache\Core\DriverAbstract->deleteItemsByTags(Array)
.........................................................
`

My guess :

in \phpfastcache\phpfastcache\src\phpFastCache\Drivers\Files\Driver.php

$object = $this->decode($content);

not always return array


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#330, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABRTZ8SyX-IshtmRXQB7IENhzN_Q8Kbjks5qZLOBgaJpZM4JUGJu
.

@ghost
Copy link
Author

ghost commented Jul 25, 2016

It is Windows 10, Files driver . I proposed a fix actually,

in \phpfastcache\phpfastcache\src\phpFastCache\Drivers\Files\Driver.php, line 122, adding " !is_array($object) || "

 if (!is_array($object) || $this->driverUnwrapTime($object)->getTimestamp() < time()) {
     @unlink($file_path);

    return null;
}

@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

I will make some test, the weird part is that i'm testing on a strict environment, so this error should appeared before oO

@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

Is that boolean true or false ?

@ghost
Copy link
Author

ghost commented Jul 25, 2016

I just applied phpfastcache for around 1 week, no problem on Windows 10 so far.

The problem happened on our Production, which is ubuntu 16.04, the cache location is /tmp. we are running nginx-fpm along with php command client for cron job.

Merci pour la reponse rapide et le superbe lib :-)

@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

Merci de lui faire confiance et de lui donner sa chance :)
Thanks for trusting it and giving it a try :)

I'm gonna made an additional check on the abstract class. May this will help.

@ghost
Copy link
Author

ghost commented Jul 25, 2016

Is that boolean true or false ?

False, I guess it may be some data corruption or something

#0 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php(122): phpFastCache\Core\DriverAbstract->driverUnwrapTime(false)

the error looks minor but it does crash the whole flow... so I dunno if I should catch that error...

@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

@ghost
Copy link
Author

ghost commented Jul 25, 2016

hmm, I see.. but wait you are showing line 57, but this error occurred at line 55

#1 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php(55): phpFastCache\Drivers\Files\Driver->driverRead(Object(phpFastCache\Drivers\Files\Item))

and the log said it is a "false"

@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

Weird, what do you have at line 122 ?
#0 /somepath/ow_libraries/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php(122)

Can you dump the whole file on gist please ?

@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

At line 57: https://github.com/PHPSocialNetwork/phpfastcache/blob/final/src/phpFastCache/Core/StandardPsr6StructureTrait.php#L57

Can you replace

                if ($driverArray) {

with

                if ($driverArray && is_array($driverArray)) {

@Geolim4
Copy link
Member

Geolim4 commented Jul 25, 2016

@phuyem Is it working for you ?

@Geolim4
Copy link
Member

Geolim4 commented Jul 28, 2016

@phuyem Bump !

@Geolim4
Copy link
Member

Geolim4 commented Jul 29, 2016

@phuyem I need your confirmation before merging this patch, thanks !

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Sorry Geolim4 for the late reply. I was on vacation.

Here is what I did in line 122 Driver.php

    if ($this->driverUnwrapTime($object)->getTimestamp() < time()) {
        @unlink($file_path);

        return null;
    }

=>

    if (!is_array($object) || $this->driverUnwrapTime($object)->getTimestamp() < time()) {
        @unlink($file_path);

        return null;
    }

I guess your solution is better. But I just don't want to test since it is production and it is working with my fix. So I guess it is an OK from me.

Again thank you for your great library.

Merci les gars!

@r0b-
Copy link
Contributor

r0b- commented Aug 2, 2016

@phuyem: I have another code at line 122 in Files/Driver.php
@Geolim4: I think the is_array check will fix the issue for now, but I'm wondering why the decode returns a boolean instead of an array from time to time...

@Geolim4
Copy link
Member

Geolim4 commented Aug 2, 2016

The main reason that the decode methods returns a boolean is that the serialized string is truncated or corrupted which leads unserialize to returns false.
This leads me to the second question: Why the hell does the if() statement is true with false boolean passed through oO ?

@Geolim4
Copy link
Member

Geolim4 commented Aug 2, 2016

@phuyem are you sure that you got the very latest version ?

@r0b-
Copy link
Contributor

r0b- commented Aug 3, 2016

Hmm your're right and additional there should be an exception in the line before that (121) because driverUnwrapData() needs an array as well, but somehow it passes this call.

Well I just updated my production environment to the latest version and if the error is thrown the next time I will take another look.

Anyways, I strongly encourage to add the is_array check!
thx

@Geolim4
Copy link
Member

Geolim4 commented Aug 3, 2016

Ok got it, i will fix it asap :)

Geolim4 added a commit that referenced this issue Aug 6, 2016
@Geolim4 Geolim4 closed this as completed in 54e4004 Aug 6, 2016
Geolim4 added a commit that referenced this issue Aug 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants