codenamejason / elmah

Automatically exported from code.google.com/p/elmah
Apache License 2.0
2 stars 0 forks source link

Flood protection with errorMail #121

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

It would be very nice to have a kind of flood protection using errorMail.

The problem occures on high frequent pages, if an error occures on every
page too many mails are sent.

Regards,

Uwe

Original issue reported on code.google.com by uwe.brau...@googlemail.com on 15 Jun 2009 at 11:28

GoogleCodeExporter commented 9 years ago
Uwe,
   Are you referring to the errorMail.net webservice from www.errormail.net?  Or are 
you speaking about a different errorMail service?

I am the developer of the errorMail.net webservice and the flood protection you 
mention is not something I had thought about.   I will look into it.

Mike
Support@ErrorMail.net

Original comment by MikeMos...@gmail.com on 23 Jul 2009 at 8:24

GoogleCodeExporter commented 9 years ago
ahh.. I see,  never mind.   I did a Google search for 'ErrorMail' and ended up 
at 
your Enhancement request.   Did not know I was smack in the middle of Forum  
-oops
You can ignore my last post.  :)

Original comment by MikeMos...@gmail.com on 23 Jul 2009 at 8:29

GoogleCodeExporter commented 9 years ago
Here's a suggestion:
The "flood protection" could be implemented in a similar way as the ASP.Net
HealthMonitoring team did for their buffer object:

For instance, here's a HealthMonitoring buffer config that would send AT MOST 
one
email per 5 minutes:
maxBufferSize="100"
urgentFlushThreshold="1"
maxFlushSize="1"
urgentFlushInterval="00:05:00"

If that config was explained in words, it would be something like this:
There is a queue of max 100 errors.
Each time there is 1 new error, we flush 1 message out of the queue. This urgent
flush can happen AT MOST once per 5 minutes intervals.

(Note that in HealthMonitoring, when the application shuts down, the buffer gets
emptied out in 'maxFlushSize' email(s) containing all of its content, whether 
or not
the interval is respected so as to never lose data)

The actual names of the configs might not be so appropriate to Elmah, but I 
think
that they expose enough information so that users get a powerful 
buffering/anti-flood
email system.

Original comment by edgard.p...@gmail.com on 16 Dec 2009 at 8:35

GoogleCodeExporter commented 9 years ago
we implemented it our selfs in ErrorMailModule:
added members:
        private DateTime m_currentMinute = DateTime.UtcNow;
        private int MAX_MAILS_PER_MINUTE = 10;
        private int m_mailCounter = 0;

in onload:
MAX_MAILS_PER_MINUTE = int.Parse(GetSetting(config, "maxMailsPerMinute", "10"));

in sendmail:
            // if one minute has passed, reset the counter
            if (m_currentMinute.AddMinutes(1) < DateTime.UtcNow)
            {
                // if there are mails, that were not sent during mail-send-pause, signal the
number of them
                if ((m_mailCounter - MAX_MAILS_PER_MINUTE) > 0)
                {
                    mail.Subject = "!!!MESSAGE OVERFLOW ENDED!!! Sending Mails startet again. Number
of mails not sent: " + (m_mailCounter - MAX_MAILS_PER_MINUTE);
                    mail.Body = "";
                    client.Send(mail);
                }
                m_currentMinute = DateTime.UtcNow;
                m_mailCounter = 0;
            }

            // if the maximum number of mails send in one minute is not reached, send the
error mail as default
            if (m_mailCounter < MAX_MAILS_PER_MINUTE)
            {
                client.Send(mail);              
            }
            // if the maximum number of mails is reached, a info message will be send
            else if (m_mailCounter == MAX_MAILS_PER_MINUTE)
            {
                mail.Subject = "!!!MESSAGE OVERFLOW!!! Maximum number of Mails per Minute
reached. Sending paused for " + 
DateTime.UtcNow.Subtract(m_currentMinute).Seconds +
"seconds.";
                mail.Body = "";
                client.Send(mail);
            }
            // if the maximum number of mails send has exceeded, no more mail should be send
            else
            {
                //Don´t send anything
            }

            //Mailcounter is raised anyway
            m_mailCounter += 1;

Original comment by uwe.brau...@googlemail.com on 25 May 2010 at 10:23

GoogleCodeExporter commented 9 years ago
Thank you Brau, I was looking for something similar.
It would be nice to have another kind of option as well.
Instead of queing all emails, wich you'll have to send sooner or later, 
resulting in a bottleneck big queue, there could be a setting not to send 
duplicate errors emails.
Let me explain better... On a high traffic site you could get struck with the 
same identical error occurring hundreds of times in a small timeframe just 
because the resource is not available for a bunch of seconds. Sending 100 
emails with the same error occurred in 3-4 seconds, both queued or not, it's 
not that useful.
Tracking the error (maybe specifing a timeframe) and preventing the mail send 
for identical error is a nice option to have.
This could be achieved with a static variable containing the last raised error 
and comparing any new error to this one (eventually checking the timeframe 
specified.. if occured within n seconds ignore sending mail), before sending 
mail.
This could be extended to logging as well, even if the most obvious benefit is 
from preventing mail spam.

Original comment by xmanig...@gmail.com on 5 May 2012 at 2:12

GoogleCodeExporter commented 9 years ago
This issue has been migrated to:
https://github.com/elmah/Elmah/issues/121
The conversation continues there.
DO NOT post any further comments to the issue tracker on Google Code as it is 
shutting down.
You can also just subscribe to the issue on GitHub to receive notifications of 
any further development.

Original comment by azizatif on 25 Aug 2015 at 8:17