Skip to content

[HttpFoundation] Use relative timestamps with MemcachedSessionHandler #48635

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
Dec 14, 2022

Conversation

tvlooy
Copy link
Contributor

@tvlooy tvlooy commented Dec 13, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature?
Deprecations?
Tickets Fix #48619
License MIT
Doc PR

Use relative timestamps. If for some reason your client is not in sync with the server clock, you at least agree about the relative TTL. Or see #48619 for a case where the memcached monotonic clock is going faster than the server and causes users to add entries that are expired on entry.

@carsonbot carsonbot added this to the 5.4 milestone Dec 13, 2022
@carsonbot carsonbot changed the title Use relative timestamps [HttpFoundation] Use relative timestamps Dec 13, 2022
@@ -77,7 +77,7 @@ protected function doRead(string $sessionId)
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
$this->memcached->touch($this->prefix.$sessionId, time() + (int) ($this->ttl ?? \ini_get('session.gc_maxlifetime')));
Copy link
Member

@derrabus derrabus Dec 13, 2022

Choose a reason for hiding this comment

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

I've read up how PHP's memcached extension interprets the values passed here: https://www.php.net/manual/en/memcached.expiration.php

tl;dr: If the passed integer is < 30 days in seconds, the value is considered to be a relative TTL. Otherwise, the value is assumed to be a UNIX timestamp.

My guess is that we added time() to be sure our relative TTL is never mistaken as a timestamp.

If we go back to relative TTLs again, I suggest we make sure our TTL is below that threshold and continue to add time() otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] Use relative timestamps [HttpFoundation] Use relative timestamps with MemcachedSessionHandler Dec 14, 2022
@nicolas-grekas
Copy link
Member

Thank you @tvlooy.

@nicolas-grekas nicolas-grekas merged commit 18a2323 into symfony:5.4 Dec 14, 2022
@fabpot fabpot mentioned this pull request Dec 16, 2022
This was referenced Dec 28, 2022
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