8000 [Fix][3.4][HttpFoundation] Fix the updating of timestamp in the MemcachedSessionHandler by tuxone · Pull Request #26443 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Fix][3.4][HttpFoundation] Fix the updating of timestamp in the MemcachedSessionHandler #26443

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

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

tuxone
Copy link
@tuxone tuxone commented Mar 7, 2018
Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

Conditions: Symfony 3.4, PHP7 and sessions handled over memcache.

Apparently memcached::touch() returns false on a subsequent call with the same parameters. Since updateTimestamp is used in AbstractSessionHandler::write()

public function write($sessionId, $data)
    {
        if (\PHP_VERSION_ID < 70000 && $this->prefetchData) {
            $readData = $this->prefetchData;
            $this->prefetchData = null;

            if ($readData === $data) {
                return $this->updateTimestamp($sessionId, $data);
            }
        }
...

the result is that write() will return false on any subsequent request within the same second causing the following error:

HP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ContextErrorException: Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown:0
Stack trace:
#0 [internal function]: Symfony\Component\Debug\ErrorHandler->handleError(2, 'session_write_c...', 'Unknown', 0, NULL)
#1 [internal function]: session_write_close()
#2 {main}
  thrown in Unknown on line 0

Can be reproduced on symfony/skeleton:3.4 adding the following code to public/index.php and performing two consecutive requests:

$session = $kernel->getContainer()->get('session');
$session->set("foo", "bar");

@tuxone tuxone force-pushed the fix/memcache-timestamp-updating branch from 77e4ae8 to d007469 Compare March 7, 2018 13:52
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Mar 12, 2018
@fabpot
Copy link
Member
fabpot commented Mar 13, 2018

Thank you @tuxone.

@fabpot fabpot merged commit d007469 into symfony:3.4 Mar 13, 2018
fabpot added a commit that referenced this pull request Mar 13, 2018
…n the MemcachedSessionHandler (Alessandro Loffredo)

This PR was merged into the 3.4 branch.

Discussion
----------

[Fix][3.4][HttpFoundation] Fix the updating of timestamp in the MemcachedSessionHandler

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Conditions: Symfony 3.4, PHP7 and sessions handled over memcache.

Apparently `memcached::touch()` returns `false` on a subsequent call with the same parameters. Since `updateTimestamp` is used in `AbstractSessionHandler::write()`

```
public function write($sessionId, $data)
    {
        if (\PHP_VERSION_ID < 70000 && $this->prefetchData) {
            $readData = $this->prefetchData;
            $this->prefetchData = null;

            if ($readData === $data) {
                return $this->updateTimestamp($sessionId, $data);
            }
        }
...
```

the result is that `write()` will return `false` on **any subsequent request within the same second** causing the following error:

```
HP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ContextErrorException: Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown:0
Stack trace:
#0 [internal function]: Symfony\Component\Debug\ErrorHandler->handleError(2, 'session_write_c...', 'Unknown', 0, NULL)
#1 [internal function]: session_write_close()
#2 {main}
  thrown in Unknown on line 0
```

Can be reproduced on `symfony/skeleton:3.4` adding the following code to `public/index.php` and performing two consecutive requests:
```
$session = $kernel->getContainer()->get('session');
$session->set("foo", "bar");
```

Commits
-------

d007469 fix the updating of timestamp in the MemcachedSessionHandler
@tuxone
Copy link
Author
tuxone commented Mar 13, 2018

Thanks for merging @fabpot

@tuxone tuxone deleted the fix/memcache-timestamp-updating branch March 13, 2018 22:36
This was referenced Apr 3, 2018
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.

4 participants
0