Cannot use a buffered swift_mailer Monolog handler with a memory spool #425

Closed
spantaleev opened this Issue Sep 28, 2012 · 48 comments

Comments

Projects
None yet
@spantaleev

The default configuration suggests that the swiftmailer service be configured with a memory spool ( https://github.com/symfony/symfony-standard/blob/master/app/config/config.yml#L59 ), so that mail sending would not slow down the request/response flow.

SwiftmailerBundle uses a KernelEvents::TERMINATE listener to flush the memory spool to a real transport ( https://github.com/symfony/SwiftmailerBundle/blob/master/EventListener/EmailSenderListener.php ).

The Symfony documentation suggests that the swift_mailer Monolog handler be used in combination with a BufferHandler. The BufferHandler flushes messages to the handler it wraps (swift mailer handler in this case) on request shutdown - https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/BufferHandler.php#L43

This means that log messages from the buffer will reach the mail handler at the end of the script's execution, which is too late to be of any use.

To summarize, the flow is now:

  1. Response send
  2. Terminate event gets fired, causing memory spool flush
  3. Script execution is about to end, so shutdown functions are called - BufferHandler passes the messages to the mail handler. The mail handler creates an "error" email message and adds it to the memory spool
  4. Script execution ends with unsent messages in the memory spool

SwiftmailerBundle could use its own register_shutdown_function(..) registration and flush again from that callback, but then Bundle registration order would be important. This seems like a bad idea.
BufferHandler using register_shutdown_function(..) is not ideal as well - maybe that should be fixed.

@jcroll

This comment has been minimized.

Show comment
Hide comment
@jcroll

jcroll Nov 27, 2012

This is causing errors for me as well. I commented out spool: { type: memory } in config.yml and monolog started mailing me errors.

jcroll commented Nov 27, 2012

This is causing errors for me as well. I commented out spool: { type: memory } in config.yml and monolog started mailing me errors.

@rvdbogerd

This comment has been minimized.

Show comment
Hide comment

+1

@kbond

This comment has been minimized.

Show comment
Hide comment
@kbond

kbond Dec 5, 2012

Contributor

Possibly related: symfony/swiftmailer-bundle#6

Contributor

kbond commented Dec 5, 2012

Possibly related: symfony/swiftmailer-bundle#6

@Seldaek

This comment has been minimized.

Show comment
Hide comment
@Seldaek

Seldaek Dec 31, 2012

Member

I think there are two steps that could be taken that would help: one would be to fix swiftmailer so that once the spool has been flushed any new email added get flushed automatically (well maybe that should be an optional mode but I guess you get my point). The other way would be to register an kernel.terminate event handler in the MonologBundle to call ->flush() on all BufferHandlers.

Member

Seldaek commented Dec 31, 2012

I think there are two steps that could be taken that would help: one would be to fix swiftmailer so that once the spool has been flushed any new email added get flushed automatically (well maybe that should be an optional mode but I guess you get my point). The other way would be to register an kernel.terminate event handler in the MonologBundle to call ->flush() on all BufferHandlers.

@ghost

This comment has been minimized.

Show comment
Hide comment

ghost commented Jan 21, 2013

+1

@Seldaek Seldaek referenced this issue in Seldaek/monolog Jan 30, 2013

Closed

Monolog + E-Mail/Swift + Buffer = no E-Mail #154

@ben-gibson

This comment has been minimized.

Show comment
Hide comment

BUMP!

@ecoleman

This comment has been minimized.

Show comment
Hide comment

👍

@richsage

This comment has been minimized.

Show comment
Hide comment
@richsage

richsage Mar 28, 2013

Contributor

+1

Contributor

richsage commented Mar 28, 2013

+1

@cordoval

This comment has been minimized.

Show comment
Hide comment
@cordoval

cordoval Apr 14, 2013

Contributor

is there a related PR on swiftmailer already @Seldaek or is it open for contributors?

👶

Contributor

cordoval commented Apr 14, 2013

is there a related PR on swiftmailer already @Seldaek or is it open for contributors?

👶

@Seldaek

This comment has been minimized.

Show comment
Hide comment
@Seldaek

Seldaek Apr 14, 2013

Member

@cordoval as far as I know nobody is on it. I think no matter how this gets fixed in symfony, the addition I mentioned above would be beneficial for SwiftMailer.

Member

Seldaek commented Apr 14, 2013

@cordoval as far as I know nobody is on it. I think no matter how this gets fixed in symfony, the addition I mentioned above would be beneficial for SwiftMailer.

@ecentinela

This comment has been minimized.

Show comment
Hide comment
@ecentinela

ecentinela Apr 19, 2013

I think that this is a bug that should be addresses as soon as posible.

I think that this is a bug that should be addresses as soon as posible.

@almacbe

This comment has been minimized.

Show comment
Hide comment

almacbe commented Apr 22, 2013

+1

@johannieto

This comment has been minimized.

Show comment
Hide comment

+1

@jjbubudi

This comment has been minimized.

Show comment
Hide comment

jjbubudi commented May 8, 2013

+1

@oste

This comment has been minimized.

Show comment
Hide comment

oste commented May 22, 2013

+1?

@peterrehm

This comment has been minimized.

Show comment
Hide comment
@peterrehm

peterrehm May 25, 2013

Contributor

I struggled some time to make sending errors work for me as well.

@fabpot How about commenting out the line with the memory spool meanwhile? Any ideas how to fix this?

Contributor

peterrehm commented May 25, 2013

I struggled some time to make sending errors work for me as well.

@fabpot How about commenting out the line with the memory spool meanwhile? Any ideas how to fix this?

@maurotdo

This comment has been minimized.

Show comment
Hide comment
@maurotdo

maurotdo May 31, 2013

This issue, and the needed workaround, should be noted in the documentation. Today i spent a fair amount of time trying to understand the problem before finding this issue. Or temporarily disable the cookbook recipe about mailing logs.

This issue, and the needed workaround, should be noted in the documentation. Today i spent a fair amount of time trying to understand the problem before finding this issue. Or temporarily disable the cookbook recipe about mailing logs.

@gintro

This comment has been minimized.

Show comment
Hide comment

gintro commented Jun 2, 2013

+1

@cordoval

This comment has been minimized.

Show comment
Hide comment
@cordoval

cordoval Jun 8, 2013

Contributor

working on this now as it is critical to my needs too right now

Contributor

cordoval commented Jun 8, 2013

working on this now as it is critical to my needs too right now

@tvlooy tvlooy referenced this issue in symfony/symfony-docs Jun 19, 2013

Closed

Document spool type #2742

@jrobeson

This comment has been minimized.

Show comment
Hide comment
@jrobeson

jrobeson Jun 22, 2013

@cordoval : so what exactly are you trying to do about this issue?

@cordoval : so what exactly are you trying to do about this issue?

@dotlabel-chris dotlabel-chris referenced this issue in symfony/symfony-docs Jul 17, 2013

Closed

Update monolog_email.rst #2830

@bicpi

This comment has been minimized.

Show comment
Hide comment

bicpi commented Aug 1, 2013

+1

@guimonz

This comment has been minimized.

Show comment
Hide comment

guimonz commented Aug 14, 2013

+1

@guimonz

This comment has been minimized.

Show comment
Hide comment
@guimonz

guimonz Aug 14, 2013

Also, a workaround until they fix it: downgrade swiftmailer and monolog

Change your composer.json to have these two guys below.
"symfony/swiftmailer-bundle": "<2.2.5",
"symfony/monolog-bundle": "<2.2.5",

This fixed it for me.

guimonz commented Aug 14, 2013

Also, a workaround until they fix it: downgrade swiftmailer and monolog

Change your composer.json to have these two guys below.
"symfony/swiftmailer-bundle": "<2.2.5",
"symfony/monolog-bundle": "<2.2.5",

This fixed it for me.

@Seldaek

This comment has been minimized.

Show comment
Hide comment
@Seldaek

Seldaek Aug 14, 2013

Member

How about "they" tell you to fix it yourself if it matters so much? This
is open source sir. Whining and writing +1 doesn't get anything done.

Member

Seldaek commented Aug 14, 2013

How about "they" tell you to fix it yourself if it matters so much? This
is open source sir. Whining and writing +1 doesn't get anything done.

@pkraeutli

This comment has been minimized.

Show comment
Hide comment
@pkraeutli

pkraeutli Aug 14, 2013

It works on my machine.

It works on my machine.

@guimonz

This comment has been minimized.

Show comment
Hide comment
@guimonz

guimonz Aug 14, 2013

@Seldaek I'm sorry if I somehow offended you.
+1 is to help the maintainers to know how many people is being affected.
The intention was to share a workaround that might help people in the same situation.

guimonz commented Aug 14, 2013

@Seldaek I'm sorry if I somehow offended you.
+1 is to help the maintainers to know how many people is being affected.
The intention was to share a workaround that might help people in the same situation.

@Seldaek

This comment has been minimized.

Show comment
Hide comment
@Seldaek

Seldaek Aug 14, 2013

Member

I am offended because it is quite clear that it's a bad issue, emails not being sent sucks. I offered two suggestions for a fix 8 months ago. Neither of those options sounds really hard to implement, but in the meantime all that happened is 10 people saying +1, and cordoval trying to fix it and then vanishing. It's not about "they", or "the maintainers". There are no maintainers. We are a community. Everyone is busy. +1s only spam people and make already busy people waste time. A patch is worth a thousand +1s. That is all.

Member

Seldaek commented Aug 14, 2013

I am offended because it is quite clear that it's a bad issue, emails not being sent sucks. I offered two suggestions for a fix 8 months ago. Neither of those options sounds really hard to implement, but in the meantime all that happened is 10 people saying +1, and cordoval trying to fix it and then vanishing. It's not about "they", or "the maintainers". There are no maintainers. We are a community. Everyone is busy. +1s only spam people and make already busy people waste time. A patch is worth a thousand +1s. That is all.

@cordoval

This comment has been minimized.

Show comment
Hide comment
@cordoval

cordoval Aug 14, 2013

Contributor

yeah @guimonz i have gone back and back to this issue, wanting to fix it, but man busy, but yeah I agree with @Seldaek don't expect others to do it, have initiative rather, but no +1 when it is already marked as needed 👶
i vanish for a reason but always those things and hints like the reasons are helpful when there is time

Contributor

cordoval commented Aug 14, 2013

yeah @guimonz i have gone back and back to this issue, wanting to fix it, but man busy, but yeah I agree with @Seldaek don't expect others to do it, have initiative rather, but no +1 when it is already marked as needed 👶
i vanish for a reason but always those things and hints like the reasons are helpful when there is time

@guimonz

This comment has been minimized.

Show comment
Hide comment
@guimonz

guimonz Aug 14, 2013

@Seldaek Didn't know +1 was annoying, I thought it was the standard way to upvote issues in github for the lack of a better alternative.
I'd love to help but I'm also really busy (startup launch in 6 weeks). After things calm down on my end, if nobody fixed it yet, I'll do it.

guimonz commented Aug 14, 2013

@Seldaek Didn't know +1 was annoying, I thought it was the standard way to upvote issues in github for the lack of a better alternative.
I'd love to help but I'm also really busy (startup launch in 6 weeks). After things calm down on my end, if nobody fixed it yet, I'll do it.

@Seldaek

This comment has been minimized.

Show comment
Hide comment
@Seldaek

Seldaek Aug 26, 2013

Member

So thanks to @pkraeutli this is now fixed in https://github.com/symfony/MonologBundle/releases/tag/v2.4.1 as long as you use a dev version of latest symfony. Not sure if it will be in the 2.3.4 or if it waits for 2.4.0 on the symfony side.

Member

Seldaek commented Aug 26, 2013

So thanks to @pkraeutli this is now fixed in https://github.com/symfony/MonologBundle/releases/tag/v2.4.1 as long as you use a dev version of latest symfony. Not sure if it will be in the 2.3.4 or if it waits for 2.4.0 on the symfony side.

@kbond

This comment has been minimized.

Show comment
Hide comment
@kbond

kbond Sep 20, 2013

Contributor

Should the note about this issue be updated in this cookbook article?

http://symfony.com/doc/current/cookbook/logging/monolog_email.html

Contributor

kbond commented Sep 20, 2013

Should the note about this issue be updated in this cookbook article?

http://symfony.com/doc/current/cookbook/logging/monolog_email.html

@jcroll

This comment has been minimized.

Show comment
Hide comment
@jcroll

jcroll Sep 20, 2013

I think Symfony will have to tag a new release before it works, unless you are on dev-master.

jcroll commented Sep 20, 2013

I think Symfony will have to tag a new release before it works, unless you are on dev-master.

garak pushed a commit to garak/symfony-docs that referenced this issue Nov 2, 2013

Update monolog_email.rst
Added caution note regarding monolog spooling based on the docs example.

symfony/symfony-standard#425

@bamarni bamarni referenced this issue in symfony/monolog-bundle Dec 11, 2013

Merged

Resolving parameter name before calling class_exists #54

@greg0ire

This comment has been minimized.

Show comment
Hide comment
@greg0ire

greg0ire Jan 14, 2014

I'm using symfony v2.4.1, monolog-bundle v2.4.1, and am still obliged to remove the spool: { type: memory } line if I want mails to be sent. Anyone having the same problem ?

I'm using symfony v2.4.1, monolog-bundle v2.4.1, and am still obliged to remove the spool: { type: memory } line if I want mails to be sent. Anyone having the same problem ?

@bamarni

This comment has been minimized.

Show comment
Hide comment
@bamarni

bamarni Jan 19, 2014

Contributor

@greg0ire : it is still buggy in 2.4.1 (see symfony/monolog-bundle#54), you can use the dev version until the next release.

Contributor

bamarni commented Jan 19, 2014

@greg0ire : it is still buggy in 2.4.1 (see symfony/monolog-bundle#54), you can use the dev version until the next release.

@greg0ire

This comment has been minimized.

Show comment
Hide comment
@greg0ire

greg0ire Jan 19, 2014

@bamarni : ok, thank you for this information!

@bamarni : ok, thank you for this information!

@Seldaek

This comment has been minimized.

Show comment
Hide comment
@Seldaek

Seldaek Jan 19, 2014

Member

Sorry I didn't realize there had been a fix. You should now be able to use monolog bundle 2.5 https://github.com/symfony/MonologBundle/releases/tag/v2.5.0

Member

Seldaek commented Jan 19, 2014

Sorry I didn't realize there had been a fix. You should now be able to use monolog bundle 2.5 https://github.com/symfony/MonologBundle/releases/tag/v2.5.0

@redecs

This comment has been minimized.

Show comment
Hide comment
@redecs

redecs Feb 14, 2014

Any chance for a backport to Symfony 2.3.x?

redecs commented Feb 14, 2014

Any chance for a backport to Symfony 2.3.x?

@gnugat

This comment has been minimized.

Show comment
Hide comment
@gnugat

gnugat Feb 14, 2014

@redecs : there's no need to backport, you can update MonologBundle to enjoy this fix :) .

  1. open your composer.json
  2. edit version of monolog-bundle to ~2.5
  3. save & close
  4. update your dependencies with composer update

gnugat commented Feb 14, 2014

@redecs : there's no need to backport, you can update MonologBundle to enjoy this fix :) .

  1. open your composer.json
  2. edit version of monolog-bundle to ~2.5
  3. save & close
  4. update your dependencies with composer update

@peterrehm peterrehm referenced this issue in symfony/monolog-bundle Feb 19, 2014

Closed

Error if spool config value not set #65

@stevenmusumeche

This comment has been minimized.

Show comment
Hide comment
@stevenmusumeche

stevenmusumeche May 10, 2014

I am running Symfony 2.4 and just updated to Monolog bundle 2.5 and I am having the same issue. Emails do work if I remove the spool line.

from my composer.json:

"symfony/symfony": "~2.4",
"symfony/swiftmailer-bundle": "~2.3",

What am I missing?

I am running Symfony 2.4 and just updated to Monolog bundle 2.5 and I am having the same issue. Emails do work if I remove the spool line.

from my composer.json:

"symfony/symfony": "~2.4",
"symfony/swiftmailer-bundle": "~2.3",

What am I missing?

@cordoval

This comment has been minimized.

Show comment
Hide comment
@cordoval

cordoval May 10, 2014

Contributor

just upgrade monolog bundle to 2.5

Contributor

cordoval commented May 10, 2014

just upgrade monolog bundle to 2.5

@stevenmusumeche

This comment has been minimized.

Show comment
Hide comment
@stevenmusumeche

stevenmusumeche May 10, 2014

sorry, I posted the wrong config. I already upgraded to 2.5 and have the same issue.

"symfony/monolog-bundle": "~2.5",

sorry, I posted the wrong config. I already upgraded to 2.5 and have the same issue.

"symfony/monolog-bundle": "~2.5",

@cordoval

This comment has been minimized.

Show comment
Hide comment
@cordoval

cordoval May 11, 2014

Contributor

oh hmm and it is SE? can you try to reproduce and send a branch please?

Contributor

cordoval commented May 11, 2014

oh hmm and it is SE? can you try to reproduce and send a branch please?

@stevenmusumeche

This comment has been minimized.

Show comment
Hide comment
@stevenmusumeche

stevenmusumeche May 11, 2014

This is what I am using:

"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
    "psr-0": { 
        "": "src/"
    },
    "classmap": [
        "/var/www/globals/classes/shipping.class.php"
    ],
    "files": [
        "/var/www/manager/defines.php"
    ]
},
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "~2.4",
    "doctrine/orm": "~2.2,>=2.2.3",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.5",
    "sensio/distribution-bundle": "~2.3",
    "sensio/framework-extra-bundle": "~3.0",
    "sensio/generator-bundle": "~2.3",
    "incenteev/composer-parameter-handler": "~2.0",
    "league/csv": "5.*",
    "imagine/imagine": "~0.5.0",
    "guzzlehttp/guzzle": "4.*",
    "rjkip/ftp-php": "dev-master",
    "jasonpriem/human-name-parser": "dev-master"
},

This is what I am using:

"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
    "psr-0": { 
        "": "src/"
    },
    "classmap": [
        "/var/www/globals/classes/shipping.class.php"
    ],
    "files": [
        "/var/www/manager/defines.php"
    ]
},
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "~2.4",
    "doctrine/orm": "~2.2,>=2.2.3",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.5",
    "sensio/distribution-bundle": "~2.3",
    "sensio/framework-extra-bundle": "~3.0",
    "sensio/generator-bundle": "~2.3",
    "incenteev/composer-parameter-handler": "~2.0",
    "league/csv": "5.*",
    "imagine/imagine": "~0.5.0",
    "guzzlehttp/guzzle": "4.*",
    "rjkip/ftp-php": "dev-master",
    "jasonpriem/human-name-parser": "dev-master"
},
@stevenmusumeche

This comment has been minimized.

Show comment
Hide comment
@stevenmusumeche

stevenmusumeche May 11, 2014

I am new to Github so if you could point me in the right direction on how to send a branch, I would be happy to do so.

I am new to Github so if you could point me in the right direction on how to send a branch, I would be happy to do so.

@cordoval

This comment has been minimized.

Show comment
Hide comment
@cordoval

cordoval May 11, 2014

Contributor

so you:

fork this repo, clone the origin this main repo on your folder, then reproduce and add changes commit and push to your branch. then send a PR from your fork on github to the main repo this one.

There are instructions for this in the symfony.com documentation if you ran into issues

Contributor

cordoval commented May 11, 2014

so you:

fork this repo, clone the origin this main repo on your folder, then reproduce and add changes commit and push to your branch. then send a PR from your fork on github to the main repo this one.

There are instructions for this in the symfony.com documentation if you ran into issues

@lopsided

This comment has been minimized.

Show comment
Hide comment
@lopsided

lopsided Sep 22, 2014

Works for me with sf 2.3 :)

"symfony/symfony": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.5.*",

Works for me with sf 2.3 :)

"symfony/symfony": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.5.*",
@ncatanchin

This comment has been minimized.

Show comment
Hide comment
@ncatanchin

ncatanchin Dec 8, 2014

Any way to get this working with Symfony 2.2? I tried to set monolog to ~2.5 but it won't let me.

Any way to get this working with Symfony 2.2? I tried to set monolog to ~2.5 but it won't let me.

@stof

This comment has been minimized.

Show comment
Hide comment
@stof

stof Dec 16, 2014

Member

no, there is no way. Symfony 2.2 is not maintained anymore since months: http://symfony.com/roadmap?version=2.2#checker so we won't try to backport this to an Symfony 2.2 version

Member

stof commented Dec 16, 2014

no, there is no way. Symfony 2.2 is not maintained anymore since months: http://symfony.com/roadmap?version=2.2#checker so we won't try to backport this to an Symfony 2.2 version

bubnov-mikhail pushed a commit to bubnov-mikhail/xproperty that referenced this issue May 12, 2016

Bubnov
Update monolog and swiftmailer
Use "symfony/monolog-bundle": "~2.5" to fix issue symfony/symfony-standard#425
Remove outdated app/console xproperty:routines-add:geodist and app/console xproperty:routines-add:geodist_pt commands from composer.json post update
Move swiftmailer:encryption and swiftmailer:auth_mode values into parameters.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment