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: fix handling exceptions thrown from SessionHandlerInterface #51

Merged
merged 1 commit into from
Feb 11, 2015

Conversation

fprochazka
Copy link
Contributor

I need to throw exception the SessionHandler.

Currently, when you throw an exception from there, the php thinks the session is started (it doesn't care about the exception) and Nette think it's not started, because the self::$started = TRUE; wasn't executed.

This creates a buggy state, where you cannot call $session->start() again, because it throws Nette\InvalidStateException("session_start(): session is already started")

Failing test is provided.

@fprochazka
Copy link
Contributor Author

As this is a bugfix of a thing that nobody could have ever used before... Is there any chance this might get into 2.3.0, so I can create a dependency in Kdyby/Redis?

@dg
Copy link
Member

dg commented Feb 11, 2015

Simplification?

        try {
            // session_start returns FALSE on failure only sometimes
            Nette\Utils\Callback::invokeSafe('session_start', array(), function ($message) use (& $e) {
                $e = new Nette\InvalidStateException($message);
            });
        } catch (\Exception $e) {
        }

        Helpers::removeDuplicateCookies();
        if ($e) {
            @session_write_close(); // this is needed
            throw $e;
        }

@fprochazka
Copy link
Contributor Author

I like that! Updated.

dg added a commit that referenced this pull request Feb 11, 2015
Session: fix handling exceptions thrown from SessionHandlerInterface
@dg dg merged commit cd3b6a5 into nette:master Feb 11, 2015
@fprochazka fprochazka deleted the patch-2 branch February 11, 2015 00:24
@fprochazka
Copy link
Contributor Author

Awesome! :)

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

Successfully merging this pull request may close these issues.

2 participants