craftcms / aws-s3

Amazon S3 volume type for Craft CMS.
https://plugins.craftcms.com/aws-s3
MIT License
61 stars 28 forks source link

Credentials.php is not able to unserialise the cached tokenKey #149

Open jordikroon opened 2 years ago

jordikroon commented 2 years ago

Description

We sometimes see an error that is triggered by the awd-sdk caused by the aws-s3 plugin. The error is fairly vague, and most of our projects seem to have this issue.

Overall the plugin is working as it should, but at random moments we receive the error:

yii\base\ErrorException

/home/tde/domains/domain.tld/releases/42/vendor/aws/aws-sdk-php/src/Credentials/Credentials.php in yii\base\ErrorHandler::handleError

Trying to access array offset on value of type null

The full path this error is taking is as following: createAdapter is calling _getConfigArray then buildConfigArray with a valid access key and secret.

This is then calling the buildConfigArray method where it is reaching the following block of code:

if (Craft::$app->cache->exists($tokenKey) && !$refreshToken) {
    $cached = Craft::$app->cache->get($tokenKey);
    $credentials->unserialize($cached);
}

The unserialize method is receiving a parameter with value false. It seems that even though $tokenKey exists, it is false.

Something like this would most likely fix the issue:

if (!$refreshToken && $cached = Craft::$app->cache->get($tokenKey)) {
    $credentials->unserialize($cached);
}