Skip to content

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

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

wants to merge 2 commits into from

Conversation

digilist
Copy link
Contributor

This improves the error message that is thrown if a session write fails (see #20807)

As there was no way to get the actual handler, I introduced a method on the SessionHandlerProxy. I hope that's okay, otherwise please give me a hint on what to do.

Q A
Branch? 2.8
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20807
License MIT

/**
* @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

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.

@nicolas-grekas nicolas-grekas added this to the 2.8 milestone Jan 29, 2017
@nicolas-grekas
Copy link
Member

Status: needs work

@nicolas-grekas
Copy link
Member

Instead of relying on some external error handler to trigger the exception, I'd suggest to register a temporary error handler that does the throw.

@digilist
Copy link
Contributor Author

That is a good idea! The code is much cleaner now.

$handler = $handler->getHandler();
}

$message = sprintf(
Copy link
Member

Choose a reason for hiding this comment

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

this can be inlined in the trigger_error() call

@fabpot
Copy link
Member

fabpot commented Mar 5, 2017

Thank you @digilist.

@fabpot fabpot closed this Mar 5, 2017
fabpot added a commit that referenced this pull request Mar 5, 2017
… (digilist)

This PR was submitted for the 2.8 branch but it was merged into the 3.3-dev branch instead (closes #21421).

Discussion
----------

Use proper error message when session write fails #20807

This improves the error message that is thrown if a session write fails (see #20807)

As there was no way to get the actual handler, I introduced a method on the SessionHandlerProxy. I hope that's okay, otherwise please give me a hint on what to do.

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20807
| License       | MIT

Commits
-------

c7a44be Use proper error message when session write fails #20807
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants