weixin_39699670
weixin_39699670
2020-12-31 08:40

session_regenerate_id(): Session object destruction failed. ID: user (path: )

This issue has originally been reported by at https://github.com/yiisoft/yii2/issues/12821. Moved here by .

session_regenerate_id(): Session object destruction failed. ID: user (path: ) after upgrade to 2.0.10.

What steps will reproduce the problem?

  1. Add this component config:

   'session' => [
       'class' => 'yii\redis\Session',
       'redis' => [
           'hostname' => 'localhost',
       ],
       'timeout' => 10,
   ],
   
  1. Log in to the application.
  2. Wait 10 seconds.
  3. Refresh the application page.

What is the expected result?

No warning.

What do you get instead?

PHP Warning – yii\base\ErrorException

session_regenerate_id(): Session object destruction failed. ID: user (path: ) 1. in vendor/yiisoft/yii2/web/Session.php at line 282

 php
     * Please refer to <http:> for more details.
     *  boolean $deleteOldSession Whether to delete the old associated session file or not.
     */
    public function regenerateID($deleteOldSession = false)
    {
        if ($this->getIsActive()) {
            // add @ to inhibit possible warning due to race condition
            // https://github.com/yiisoft/yii2/pull/1812
            if (YII_DEBUG && !headers_sent()) {
                session_regenerate_id($deleteOldSession); // </http:>

Additional info

| Q | A | | --- | --- | | Yii version | 2.0.10 | | PHP version | 7.0.12 | | Operating system | Alpine Linux 3.4 |

该提问来源于开源项目:yiisoft/yii2-redis

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

16条回答

  • Myinxiaoqiang Myinxiaoqiang 1月前

    这个错误如何修改

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    Fixed. please try it.

    点赞 评论 复制链接分享
  • weixin_39549312 weixin_39549312 3月前

    It works, thanks!

    点赞 评论 复制链接分享
  • weixin_39648824 weixin_39648824 3月前

    I am getting this error still. using redis for session in AWS

    PHP Warning – yii\base\ErrorException session_regenerate_id(): Session object destruction failed. ID: user (path: /var/lib/php/7.0/session)

    1. in /var/www/cognitives/vendor/yiisoft/yii2/web/Session.php at line 282
    2. yii\base\ErrorHandler::handleError(2, 'session_regenerate_id(): Session...', '/var/www/cognitives/vendor/yiiso...', 282, ...)
    3. in /var/www/cognitives/vendor/yiisoft/yii2/web/Session.php at line 282 – session_regenerate_id(true)
    4. in /var/www/cognitives/vendor/yiisoft/yii2/web/User.php at line 626 – yii\web\Session::regenerateID(true)
    5. in /var/www/cognitives/vendor/yiisoft/yii2/web/User.php at line 248 – yii\web\User::switchIdentity(common\models\User, 2592000)

    'session' => [ 'class' => 'yii\redis\Session', 'redis' => 'redis' ],

    'redis' => [ 'class' => 'yii\redis\Connection', 'hostname' => 'cccccccc.amazonaws.com', 'port' => 6379, 'database' => 0, ],

    点赞 评论 复制链接分享
  • weixin_39549312 weixin_39549312 3月前

    The fix is not yet released (which is a shame), but you can use the "dev-master" version for "yii2-redis" package in your composer.json:

    json
    "require": {
        "yiisoft/yii2-redis": "dev-master"
    }
    
    点赞 评论 复制链接分享
  • weixin_39648824 weixin_39648824 3月前

    Thanks EvgenyOrekhov. I will check the dev-master branch.

    点赞 评论 复制链接分享
  • weixin_39817391 weixin_39817391 3月前

    what's the holdup for a release of 2.0.6? I ran into this bug today.

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    Seems nothing critical is on the list. I'll check in detail soon.

    点赞 评论 复制链接分享
  • weixin_39979489 weixin_39979489 3月前

    I encounter this bug today. Please release this fix.

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    I'm on it: https://github.com/yiisoft/yii2-redis/commits/master

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    Yes, the behavior in debug mode is different in 2.0.10. It doesn't ignore errors anymore. What should be fixed is the cause of this error.

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.fixes-custom-session-handler

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    But that should not be an issue since https://github.com/yiisoft/yii2-redis/blob/master/Session.php#L142 is casted to boolean.

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    Related fix in 1.1: https://github.com/yiisoft/yii/commit/45d6a7d51be2ea12a935a94511290cb9670706d9

    点赞 评论 复制链接分享
  • weixin_39965075 weixin_39965075 3月前

    Session was removed via TTL redis param, so when you destroy session, DEL command returns false. And false interpeted as a failed session destruction.

    点赞 评论 复制链接分享
  • weixin_39616477 weixin_39616477 3月前

    Thank you for finding it out.

    点赞 评论 复制链接分享