Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use proper error message when session write fails #20807 #21421

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use proper error message when session write fails #20807
  • Loading branch information
digilist committed Jan 26, 2017
commit 13434b1a18e76cf9c138101bf129dfd63ed55aec
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,29 @@ public function regenerate($destroy = false, $lifetime = null)
*/
public function save()
{
session_write_close();
try {
session_write_close();
} catch (\ErrorException $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work in prod, as notices and warnings are not turned into ErrorException exceptions there.

Code must not be written by assuming that the error handler has this behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently the session write fails silently in production.

I updated the code to check the last error message and throw a E_USER_WARNING with the corrected message. However, the warning is not logged by default.

Alternatively, we can throw an Excpetion if the write fails, as it is an error anyway. However, it does break BC.

// The default PHP error message is not very helpful, as it does not give any information on the curently
// used save handler.
// Therefore, we catch this exception and throw a new exception is a proper exception message
$handler = $this->getSaveHandler();
if ($handler instanceof SessionHandlerProxy) {
$handler = $handler->getHandler();
}

throw new \ErrorException(
sprintf(
'session_write_close(): Failed to write session data with %s handler',
get_class($handler)
),
$e->getCode(),
$e->getSeverity(),
$e->getFile(),
$e->getLine(),
$e
);
}

if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
// This condition matches only PHP 5.3 with internal save handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public function __construct(\SessionHandlerInterface $handler)
$this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user';
}

/**
* @return \SessionHandlerInterface
*/
public function getHandler(): \SessionHandlerInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type is a no-go as Symfony supports PHP 5.x

{
return $this->handler;
}

// \SessionHandlerInterface

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.