Skip to content

[Lock] Add $prefix parameter to avoid collision with FlockStore #57857

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

jdecool
Copy link
Contributor

@jdecool jdecool commented Jul 28, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

Currently if two Symfony projects are hosted on the same server and used the same key for a lock using the default FlockStore, the two applications shared the same lock.

So I suggest adding a prefix in the FlockStore constructor to isolate the lock to the current project and avoid collision.

This prefix could be initialized with the kernel.secret parameter by default.

To avoid BC, I add the flock-exclusive lock key configuration.

I know this could be done by changing the path a the FlockStore, but this "exclusive lock" could be the default behaviour of Symfony in the next major release.

@jdecool jdecool force-pushed the lock-flock-collision branch from 3ed7270 to ec32409 Compare July 28, 2024 12:38
@symfony symfony deleted a comment from carsonbot Jul 28, 2024
@OskarStark OskarStark changed the title [Lock] Add prefix argument to avoid collision with FlockStore [Lock] Add $prefix parameter to avoid collision with FlockStore Aug 2, 2024
7.2
---

* Add parameter `$prefix` to `FlockStore::__construct()`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Add parameter `$prefix` to `FlockStore::__construct()`
* Add `$prefix` parameter to `FlockStore::__construct()`

*
* @throws LockStorageException If the lock directory doesn’t exist or is not writable
*/
public function __construct(?string $lockPath = null)
public function __construct(?string $lockPath = null, ?string $prefix = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public function __construct(?string $lockPath = null, ?string $prefix = null)
public function __construct(
?string $lockPath = null,
private ?string $prefix = null,
)

We can use CPP (constructor property promotion here)

@jderusse
Copy link
Member

jderusse commented Aug 2, 2024

Didn't the $lockPath parameter solve the issue?

@jdecool
Copy link
Contributor Author

jdecool commented Aug 2, 2024

Didn't the $lockPath parameter solve the issue?

It does.

But by default, everything is written in the temp directory and if two Symfony projects use the default configuration they will share the lock.

The purpose of this PR is to provide a way to insulate by default the lock per Symfony instance (using the APP_SECRET).

@jdecool
Copy link
Contributor Author

jdecool commented Sep 29, 2024

What about this PR ?

The idea is to allow multiple Symfony project to use flock LockStore on the same server without being block each other by default.

@nicolas-grekas
Copy link
Member

I would do it diffently: since by default we have a shared lock space, we should still do that, or we might break apps.
Then, for apps that need split lock spaces, each could define a dedicated $lockPath. We might make this easy by adding a namespace or prefix config option.
But since $lockPath already provides a way to do this split, we should leverage it. And I would definitely not use the secret for that (and I wouldn't split by default).

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
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