This project is read-only.

Service Hangs and Consumes Processor

Nov 19, 2011 at 3:13 AM

I kept getting a hanging service with the latest code base and a processor utilization of 99%. After debugging it locally I tracked it down to the RegEx.Match call in the ParseAddress method. I reverted just that method back to the previous revision on my local copy and I no longer have that problem. The method now reads:

 

        private string ParseAddress(string input)
        {
            Match match = Regex.Match(input, "<.+@.+>", RegexOptions.IgnoreCase);
            string matchText;
            if (match.Success)
            {
                matchText = match.Value.Remove(0, 1);
                matchText = matchText.Remove(matchText.Length - 1, 1);
                return matchText;
            }
            return null;
        }

I still have the service crash intermittently though. Not sure why. I'm pretty sure it's unrelated to the RegEx issue. Any pointers would be much appreciated.

Nov 20, 2011 at 12:08 AM

Hi robertjneal,

I have actually just been experiencing this problem, but have corrected it and will not be a problem in the new version.

We are currently in the process of applying a number of fixes to the service and will be uploading the new copy in the next short while.

Best Regards,

ComputereOne

Nov 22, 2011 at 1:59 AM

Hm, looks like my fix didn't fix the processor consumption problem. That bug has resurfaced. If you can let me know where to look to fix it until you release the update it would be very helpful.

Nov 23, 2011 at 4:38 AM
Edited Nov 23, 2011 at 4:46 AM

Okay, so I think I got it working. I was getting this on my client: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

After that error the second email I sent would crash the service.

I added this line to the sendnoquit case:  session.Send(msg_goodbye);

So now that case reads:

 

                case "sendnoquit":
                    if (session.lastCommand == 6)
                    {
                        SendEmail(session.FROM, session.DATA);
                        session.Send(msg_goodbye);
                        session.lastCommand = 3;
                    }
                    session.client.Client.Close();
                    break;

It works locally. I'm pushing it to the server now and hoping for the best.

 

UPDATE: Doesn't work on server. I'm still looking for the solution.

Nov 24, 2011 at 5:25 PM

FINALLY figured it out. There's a bug in this program. It never responds to the quit command because it never resets after waiting for the <crlf>.<crlf> for data. I fixed it and now it's super fast and it works! Here are the changes:

Change 6 to 7 on line 216

 

                case "quit":
                    if (session.lastCommand == 7)
                    {
                        SendEmail(session.FROM, session.DATA);
                    }
                    session.Send(msg_goodbye);
                    session.lastCommand = 3;
                    session.client.Client.Close();
                    break;


Add the or (||) in the conditional on line 249

                case "sendnoquit":
                    if (session.lastCommand == 6 || session.lastCommand == 7)
                    {
                        SendEmail(session.FROM, session.DATA);
                        session.lastCommand = 3;
                    }
                    session.client.Client.Close();
                    break;

Change the session.lastCommand right after line 326

            if (session.recievedData != "DATA\r\n")
            {
                session.DATA = session.recievedData;
                session.Send(msg_ok);
                session.lastCommand = 7;
            }

Happy Thanksgiving!!

Nov 27, 2011 at 1:55 AM

Hi robertjneal,

Thank you very much for finding and fixing the bug, myself and the rest of the people using this service really appreciate it.

I have made the suggested changes and uploaded the new Source Code and Windows Service.

Best Regards,

ComputerOne

Jan 9, 2012 at 12:17 PM
Edited Jan 9, 2012 at 12:18 PM

Hi, I had similar issues with the RegEx.

changed it to            

 Match match = Regex.Match(input, "<.+@.+>", RegexOptions.IgnoreCase);

it indeed hangs if the regex fails.

Works fine now.

the address that failed : noreply@subdomain.domain.com