Skip to content

[Messenger] DeduplicateStamp cannot be serialized (if certain lock stores are used) #60667

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
kbond opened this issue Jun 3, 2025 · 6 comments

Comments

@kbond
Copy link
Member

kbond commented Jun 3, 2025

Symfony version(s) affected

7.3

Description

The key cannot be serialized.

Exception is thrown when serializing (using the PHP serializer) DeduplicateStamp because some lock stores (ie flock) prevent the Key from being serialized.

Ref: zenstruck/messenger-test#95

(#60659 also has issues with DeduplicateStamp but with the symfony/serializer)

How to reproduce

When using the PHP messenger serializer, a flock lock store, send an async message with a DeduplicateStamp.

Possible Solution

No response

Additional Context

No response

@VincentLanglet
Copy link
Contributor

It's kinda tricky because when the stamp is generated we only provide a key and cannot know which store will use this key.

Key is flagged as non serializable for some store when calling aquire in the middleware

If we remove the Key and don't serialize it, the lock will never be released.
And we cannot easily check if the Store will prevent serializing the Key...

Do you have some idea/solution in mind ? @kbond

@kbond
Copy link
Member Author

kbond commented Jun 3, 2025

Does the key object need to be serialized? Can we just serialize the resource string? I'm not super familiar with the lock component.

@stof
Copy link
Member

stof commented Jun 4, 2025

Serializing it is required, as this is what allows the messenger consumer to become the owner of the lock acquired in the process dispatching the stamped message. The Key instance is the owner of the lock.

Using another key for the same resource string has a totally different meaning. It would try to acquire a conflicting lock (which would fail to be acquired as the other one is not released)

@stof
Copy link
Member

stof commented Jun 4, 2025

See https://symfony.com/doc/current/components/lock.html#serializing-locks for the documentation about serializing locks.

@VincentLanglet
Copy link
Contributor

It might be great to expose a method on lockFactory/store to know earlier that it's incompatible with serializer.

@kbond
Copy link
Member Author

kbond commented Jun 4, 2025

Seeing as it is (will be) documented as "only supporting serializable locks", I don't think there's anything to do here. It isn't a big anyway.

@kbond kbond closed this as completed Jun 4, 2025
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

4 participants