Skip to content
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

Lazy loaded Swift_Message can cause unserialize errors when using file spool #117

Closed
mekras opened this issue Apr 3, 2015 · 11 comments
Closed

Comments

@mekras
Copy link
Contributor

mekras commented Apr 3, 2015

When storing message in file it will be serialized with class name like Swift_Message_000000003b027a18000000005cb90b1f. After container rebuild this name will change. So if cache was cleared after message stored but before swiftmailer:spool:send command executed there will be error Catchable Fatal Error: Argument 1 passed to Swift_Transport_MailTransport::send() must implement interface Swift_Mime_Message, instance of __PHP_Incomplete_Class given.

This is a rare but troublesome case.

@mekras
Copy link
Contributor Author

mekras commented Jun 8, 2015

How about adding option to disable lazy loading here?

@Seldaek
Copy link
Member

Seldaek commented Jun 19, 2015

Do you want to send a PR for it? I don't see a problem with making it optional, although it would be nicer if it was fixed upstream.. I find it strange that such classes end up in the spool. I would think the lazy loading is just delaying the creation until we use the message, but once it is sent to Swift it should really store it in a way that can be reloaded not based on the cache settings :/

@mekras
Copy link
Contributor Author

mekras commented Jun 22, 2015

OK, I'll try.

@mekras
Copy link
Contributor Author

mekras commented Jun 23, 2015

@Seldaek wrote:

I would think the lazy loading is just delaying the creation until we use the message

Yes, for this purpose a proxy class with a random name is created instead of Swift_Message class. I think this is not an upstream problem but a reasonable solution.

To keep Swift_Message lazy its descendant in MonologBundle can be created with custom serialization method. Method can check for VirtualProxyInterface on $this and return serialization of the real message object, not his proxy. It's quite cumbersome but how about this?

@mekras
Copy link
Contributor Author

mekras commented Jun 23, 2015

PR to add "lazy" option: #132

@Seldaek
Copy link
Member

Seldaek commented Jul 12, 2015

I can merge your PR as a workaround but I think the proxy class created by symfony should handle serialization gracefully (i.e. instantiate itself fully at that point and then serialize the instance). Or did I misunderstand you? Still sounds like something that could be fixed in symfony.

@stof
Copy link
Member

stof commented Aug 1, 2015

@Seldaek the problem is that serialize($object) will always register the class of the object being serialized, and reuse the same class on unserialization. And this is outside the control of the object.

so the class must exist again to deserialize. The only way to change that would be to change the calling code to stop using PHP serialization

Seldaek added a commit that referenced this issue Aug 1, 2015
#117: Add option to control swift_mailer lazy loading.
@Seldaek
Copy link
Member

Seldaek commented Aug 1, 2015

Oh right that sucks. I merged the workaround PR then. I guess it should be in the docs that if not using the memory spool people should disable lazy logging as well? Or did I misunderstand that?

cc @RyanWeaver

@xabbuh
Copy link
Member

xabbuh commented Aug 2, 2015

I doubt @RyanWeaver has anything to say here. :)

/cc @weaverryan

@xabbuh
Copy link
Member

xabbuh commented Aug 4, 2015

see symfony/symfony-docs#5596

@lyrixx
Copy link
Member

lyrixx commented May 18, 2019

I'm going to close this issue as we can not dot anything here.
The class should exist in the code base to be able to unserialise it.
But @xabbuh added a not in the documentation symfony/symfony-docs@f20fd8d

Thanks

@lyrixx lyrixx closed this as completed May 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants