8000 Call to a member function isActive() on null after update to 3.3.11 Symfony version · Issue #24934 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Call to a member function isActive() on null after update to 3.3.11 Symfony version #24934

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
fjpalacios opened this issue Nov 12, 2017 · 19 comments

Comments

@fjpalacios
Copy link
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.3.11
PHP version 7.1.11
nginx version 1.12.2

It's the first time that I reported a possible bug to Symfony and English isn't my mother tongue, so I want to apologize if I can't explain something clearly.

After upgrading to Symfony 3.3.11 failed all the battery of tests for my project. Among other failures, the most repeated is that the status code of the client wasn't 200 but 500, I then manually checked the project and whenever there is written this code:

if (!$flush) {
    $status = 'POST_EDITED_PROPERLY';            
} else {
    $status = 'POST_EDITED_ERROR';
}
$this->session->getFlashBag()->add('status', $status);

It's true that there is a 500 error. And the Symfony error message is: Call to a member function isActive() on null.

The line of the log with the critical error is:

Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Call to a member function isActive() on null" at /Volumes/media/programación/www/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php line 290

The Stack Trace offered is:

Symfony\Component\Debug\Exception\FatalThrowableError:
Call to a member function isActive() on null

at vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php:290
at Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->getBag('flashes')
(vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Session.php:221)
at Symfony\Component\HttpFoundation\Session\Session->getBag('flashes')
(vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Session.php:231)
at Symfony\Component\HttpFoundation\Session\Session->getFlashBag()
(src/AppBundle/Controller/AdminController.php:201)
at AppBundle\Controller\AdminController->postsEditAction(object(Request), '17')
at call_user_func_array(array(object(AdminController), 'postsEditAction'), array(object(Request), '17'))
(vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:153)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:169)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(web/app_dev.php:29)
at require('/Volumes/media/programación/www/Symfony/web/app_dev.php')
(vendor/symfony/symfony/src/Symfony/Bundle/WebServerBundle/Resources/router.php:42)

If I can do something more and it's within my ability just let me know.

@javiereguiluz
Copy link
Member

@fjpalacios thanks for reporting this issue and for providing all that information!

I'd like to ask you which was the last Symfony version where your application worked. You said that the error happens after upgrading to 3.3.11. Were you using 3.3.10 before or it was an older version?

I'd also like to know if any of the external conditions changed after the upgrade (the PHP version, the php.ini config, the execution environment (docker or not), etc.) You probably didn't change anything ... but we need to be sure. Thanks!

@fjpalacios
Copy link
Author

@javiereguiluz yes, previously this update to 3.3.11 my project was in 3.3.10. I didn't change anything at all compared to how it was before, I don't use Docker, I don't upgraded PHP or nginx, nor changed my php.ini. Just a composer update symfony/symfony

To ensure that the problem was the update I did rm -rf vendor I changed in composer.json the version of Symfony to 3.3.10 then composer update symfony/symfony once again and now everything worked fine.

@fjpalacios
Copy link
Author

Perhaps not sufficiently explained what I wanted to say in the last paragraph (my English should be improved). When I returned to 3.3.10 to test everything worked fine, but if I upgrade to 3.3.11 the same 500 error is still there. Sorry if my previous message was well understood, but I preferred to be sure.

@javiereguiluz
Copy link
Member

@fjpalacios you explained yourself perfectly: the application works with Symfony 3.3.10 but, if you upgrade to 3.3.11 and change nothing else, the application fails.

@xabbuh
Copy link
Member
xabbuh commented Nov 13, 2017

Can you share a bit more context of the code where this call is made? Where is the session attribute in your code set, for example?

@damienthiesson
Copy link
damienthiesson commented Nov 13, 2017

We also experienced the same issue, due to this commit introduced in the 2.7.36 release: symfony/http-foundation@0d84932

For some reasons, the php session is active but the sessionHandler is not set, and this commit prevent the storage handler from setting the save handler if a session is active. This only break in the context of unit tests after instantiating a Symfony\Component\HttpKernel\Client and triggering a request.

To move on, we had to use explicitely
"symfony/http-foundation": "2.7.35",
Instead of
"symfony/http-foundation": "2.7.*"

I noticed the session is artificially created by injecting a cookie in our unit tests, which might explain the trick:

`// Get a test user to login to the system with
list($uid, $user) = $this->getTestUser();

    // Creates the web crawler client
    $client = $this->createClient([ 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' ]);

    // Sets the uid cookie so the session gets upgraded to a php session
    $cookie = new Cookie('uid', $uid);
    $client->getCookieJar()->set($cookie);
    $client->request('GET', '/login');

    // Break here.
    $crawler = $client->request('GET', '/test.php');

`

@fjpalacios
Copy link
Author

@xabbuh my project is open source, maybe you can find useful to have all of the code. Just in case: https://github.com/sargantanacode/sargantanacode

@nicolas-grekas
Copy link
Member

@sroze look like we messed up somewhere :) see also #24941

@javiereguiluz
Copy link
Member

I've updated an app to 3.3.11 and I can't reproduce this or #24941. But we're not dealing with cookies in the tests of that app, which is what causes problems for @damienthiesson.

@mzampetakis
Copy link
mzampetakis commented Nov 13, 2017

Hello, I had a similar issue today after updating from 2.8.28 to 2.8.29. I got this error:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: 
"Error: Call to a member function isActive() on null" at app/cache/prod/classes.php line 196 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 0): Error: Call to a member function isActive() on null at 
app/cache/prod/classes.php:196)"} []

This is the part of clases.php file that cause it:

public function getBag($name)
{
if (!isset($this->bags[$name])) {
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
}
if ($this->saveHandler->isActive() && !$this->started) {
$this->loadSession();
} elseif (!$this->started) {
$this->start();
}
return $this->bags[$name];
}

@cedgex
Copy link
cedgex commented Nov 13, 2017

Hello,
same problem.
updating 3.3.11 > Call to a member function isActive() on null
downgrade 3.3.10 OK
best regards

@4lxndr
Copy link
4lxndr commented Nov 13, 2017

Hey, i use the symfony/http-foundation component standalone and get the same error while updating to 3.4.x-dev ce3c40e.

code:

$session = new Session();
return $session;

greetings

@albanafmeti
Copy link

I am using Laravel 5.5.
I just run composer update today and the same bug is happening on my side.

@sroze
Copy link
Contributor
sroze commented Nov 13, 2017

That's a good point... This will happen if your PHP session is already opened. We've decided not to call the setSaveHandler method because of this call to session_set_save_handler that isn't allowed anymore in PHP 7.2. I guess we should just stop the call to session_set_save_handler and not the entire setSaveHandler method.

@sroze
Copy link
Contributor
sroze commented Nov 13, 2017

@damienthiesson could you confirm that this issue is gone with the following PR?
#24946

If this solves it (which I guess), we can merge to the 3.x branches and this should be solved for the rest of you.

@otsoga
Copy link
otsoga commented Nov 13, 2017

I had the same problem. Downgrading back to 3.3.10 fixed it.

@sev-signal
Copy link

Hi,
I'm having the same issue using the latest version of concrete5.
I just ran a composer update during the lunch and..... "Call to a member function isActive() on null "

@fabpot
< 8000 /path> Copy link
Member
fabpot commented Nov 13, 2017

We need people testing the fix from #24946 before merging and making new releases and confirming that this fixes this issue. Thanks for your help and sorry for the inconvenience.

@sev-signal
Copy link

This seems to work for me

nicolas-grekas added a commit that referenced this issue Nov 13, 2017
…kas, sroze)

This PR was merged into the 2.7 branch.

Discussion
----------

[HttpFoundation] Fix session-related BC break

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24941, #24934, #24947 and #24946
| License       | MIT
| Doc PR        | -

Conservative fix.

Commits
-------

38186aa [HttpFoundation] Add test
3eaa188 [HttpFoundation] Fix session-related BC break
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

0