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

Session Write Failed #15037

Closed
KnightYoshi opened this issue Oct 28, 2017 · 11 comments
Closed

Session Write Failed #15037

KnightYoshi opened this issue Oct 28, 2017 · 11 comments

Comments

@KnightYoshi
Copy link

KnightYoshi commented Oct 28, 2017

What steps will reproduce the problem?

Couldn't say this was the first time it happened and it happened only once on page reload - reloading a second time had no issue.

What is the expected result?

Session writes to the DB

What do you get instead?

Session write failed

Additional info

yii\base\ErrorException: session_regenerate_id(): Session write failed. ID: user (path: ) in /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/Session.php:295 Stack trace: #0 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/DbSession.php(103): yii\web\DbSession->regenerateID() #1 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/User.php(618): yii\web\DbSession->regenerateID() #2 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/User.php(292): app\components\User->switchIdentity() #3 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/User.php(674): app\components\User->loginByCookie() #4 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/User.php(188): app\components\User->renewAuthStatus() #5 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/User.php(343): app\components\User->getIdentity() #6 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/Component.php(132): app\components\User->getId() #7 /Users/KnightYoshi/workspace/www/site_project/modules/randimg/views/randimg/viewset.php(14): app\components\User->__get() #8 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/View.php(330): app\components\View->unknown() #9 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/View.php(250): app\components\View->renderPhpFile() #10 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/View.php(152): app\components\View->renderFile() #11 /Users/KnightYoshi/workspace/www/site_project/components/View.php(58): app\components\View->render() #12 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/Controller.php(381): app\components\View->render() #13 /Users/KnightYoshi/workspace/www/site_project/modules/randimg/controllers/RandimgController.php(158): app\modules\randimg\controllers\RandimgController->render() #14 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/InlineAction.php(57): app\modules\randimg\controllers\RandimgController->actionDisplay() #15 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/InlineAction.php(57): ::call_user_func_array:{/Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/InlineAction.php:57}() #16 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams() #17 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/Module.php(523): app\modules\randimg\controllers\RandimgController->runAction() #18 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/web/Application.php(102): yii\web\Application->runAction() #19 /Users/KnightYoshi/workspace/www/site_project/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest() #20 /Users/KnightYoshi/workspace/www/site_project/web/index.php(12): yii\web\Application->run() #21 {main}

Q A
Yii version 2.0.12
PHP version 7.1.6
@samdark
Copy link
Member

samdark commented Oct 28, 2017

Could be #9438 related.

@samdark
Copy link
Member

samdark commented Oct 28, 2017

Do you write any additional data into database?

@yii-bot
Copy link

yii-bot commented Oct 28, 2017

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

@KnightYoshi
Copy link
Author

It also writes the user ID to the session table on log in to be able to invalidate all of the user's sessions.

@samdark
Copy link
Member

samdark commented Oct 28, 2017

Try code from master along with debug mode. It will reveal real reason behind the error.

@KnightYoshi
Copy link
Author

Try what from the master branch? I have looked in at the debugger. That's how I got the stack trace, because I had already refreshed. The stack trace says session_regenerate_id() threw an exception. I'm not sure what more I'm suppose to be able to find out, especially since it seems to have been a one-off error.

@samdark
Copy link
Member

samdark commented Oct 28, 2017

Well, the reason. In 2.0.12 you'll see this error. In master you may see, for example, an exception that occurred during saving values to DB with your custom handler that resulted in session_regenerate_id() errors. If that's not the case then it's different issue.

@KnightYoshi
Copy link
Author

I use this for the the session module config to include the user ID.

'writeCallback' => function ($session) {
	return [
		'user_id' => Yii::$app->user->id
	];
}

@samdark
Copy link
Member

samdark commented Oct 28, 2017

I'd check if user isn't guest here first.

@KnightYoshi
Copy link
Author

I've gone ahead and added a ternary to set the user ID or explicitly set null, but I'm still not sure if that's what caused the issue; since if the user is not signed in that would be null anyway.

Like I said, though. That's the first time that happened and it only happened once. So it's hard to say, but I added checking it anyway per your recommendation.

@samdark
Copy link
Member

samdark commented Oct 29, 2017

I'm closing the issue for now since there's not enough info to fix anything. If it will appear again, please let us know.

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

No branches or pull requests

3 participants