feliperochadev / elmah

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

Re-entrancy problems in ErrorMailModule #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Configure Elmah to email errors using ErrorMailModule
2. Don't configure the SMTP host
3. Generate a test error

What is the expected output? What do you see instead?

I expect Elmah to be unable to send the email (because the SMTP host 
doesn't exist), and then exit gracefully!
Instead, this raises an exception in ErrorMailModule.SendMail, which Elmah 
then tries to email.
But it can't, so it raises an exception, which Elmah then tries to email.
etc, etc, etc!!

cref ErrorLogModule.LogException which has this code:

            try
            {
                Error error = new Error(e, context);
                ErrorLog log = GetErrorLog(context);
                string id = log.Log(error);
                entry = new ErrorLogEntry(log, id, error);
            }
            catch (Exception localException)
            {
                //
                // IMPORTANT! We swallow any exception raised during the 
                // logging and send them out to the trace . The idea 
                // here is that logging of exceptions by itself should not 
                // be  critical to the overall operation of the 
application.
                // The bad thing is that we catch ANY kind of exception, 
                // even system ones and potentially let them slip by.
                //

                Trace.WriteLine(localException);
            }

Original issue reported on code.google.com by jamesdriscoll71 on 19 Jul 2008 at 10:28

GoogleCodeExporter commented 9 years ago
You mean to say it enters an infinite loop?

Original comment by azizatif on 19 Jul 2008 at 10:43

GoogleCodeExporter commented 9 years ago
I believe that ASP.NET specifically caters for re-entrancy issues when it comes 
to 
reporting unhandled exceptions via the Error event.

Original comment by azizatif on 19 Jul 2008 at 11:38

GoogleCodeExporter commented 9 years ago
It continually raises the same exception when trying to send the email.
Because Elmah is trapping for any application errors, it catches the unhandled 
ones 
in SendMail. 

Take this stripped down web.config...

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="elmah">
      <section name="errorMail" type="Elmah.ErrorMailSectionHandler, Elmah" 
requirePermission="false" />
    </sectionGroup>
    </configSections>
    <elmah>
    <errorMail from="xyz@elmah.com" to="abc@elmah.com" />
  </elmah>
    <system.web>
        <httpHandlers>
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, 
Elmah"/>
        </httpHandlers>
        <httpModules>
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
        </httpModules>
    </system.web>
</configuration>

... ensure there is no <system.net><mailSettings><smtp> settings...
Then run this through Visual Studio. When you exit the browser you will get an 
error 
stating that WebDev.WebServer.exe has stopped working.

If you run the same code in debug mode you will see that 
ErrorMailModule.SendMail 
keeps raising an exception!

Original comment by jamesdriscoll71 on 20 Jul 2008 at 6:22

GoogleCodeExporter commented 9 years ago
I can't seem to reproduce the described behavior with respect to re-entrancy. 
What I 
do see is that leaving out the SMTP server configuration altogether does raise 
an 
exception and brings down the whole WebDev.WebServer.exe process. This is 
normal 
because the rules about unhandled exceptions on threads from the thread pool 
changes 
with .NET Framework 2.0 (see http://support.microsoft.com/kb/911816 for more). 
What 
I don't see at all is that, "it continually raises the same exception."

Original comment by azizatif on 20 Jul 2008 at 9:52

GoogleCodeExporter commented 9 years ago
1. I'm doing this in Visual Studio 2008 with a project targetted to v3.5 of the 
Framework.
2. Set a breakpoint in ErrorMailModule.SendMail
3. Run the scenario described previously
4. I keep hitting my breakpoint in SendMail

I'll zip up a project later if necessary!

Original comment by jamesdriscoll71 on 21 Jul 2008 at 9:25

GoogleCodeExporter commented 9 years ago
> I'll zip up a project later if necessary!

That'll definitely help a lot, as an attachment to your issue comment.

Original comment by azizatif on 21 Jul 2008 at 9:28

GoogleCodeExporter commented 9 years ago
Atif, you're right... there is no re-entrancy. I'm going to blame that part on 
jet-
lag!! I was incorrectly interpreting what I was seeing... OOPS!!!

However, it's still pertinent to ask, is it right that a badly configured 
web.config 
brings down the web server? Should we be trapping errors in sending the email 
and 
discarding them in the same way that ErrorLogModule.LogException does??

Original comment by jamesdriscoll71 on 27 Jul 2008 at 8:48

GoogleCodeExporter commented 9 years ago
>>
However, it's still pertinent to ask, is it right that a badly configured 
web.config 
brings down the web server? Should we be trapping errors in sending the email 
and 
discarding them in the same way that ErrorLogModule.LogException does??
<<

Fair point to bring up but I would open that up as a separate issue from this 
one to 
keep the discussion and subject relevant. Meanwhile, I'm going to close this 
issue 
as invalid.

Original comment by azizatif on 28 Jul 2008 at 8:41

GoogleCodeExporter commented 9 years ago
Interesting that this should have been marked as invalid because I'm seeing 
exactly the behavior described.
I have localhost configured for SMTP but that only works for my production 
environment.
Meanwhile I was debugging another issue on my workstation which by first 
receiving a different exception lead to this SMTP infinite loop exception.
I realize I could make this go away by changing config for debugging etc. I 
don't believe that an infinite loop is acceptable under any condition.

Original comment by fangsp...@gmail.com on 6 Aug 2014 at 9:13