Intermittent problem yesterday with "existing connection was forcibly closed"

Answered Intermittent problem yesterday with "existing connection was forcibly closed"

  • Saturday, April 28, 2012 8:26 AM
     
     

    My web app writes a minimal amount of data to an Azure DB every 10 minutes via a sproc and tableadaptor. It's my first SQL Azure app and has been running for about a week.

    Today it hit the notorious "A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)"

    This happened intermittently between 4:00 pm PST and 7:00 pm PST - it ran fine before and after. I have dumb retry logic that trys five times and backs off a second each time. In no case did the backoff logic result in a successful insert.

    I don't get it - is the service just fundamentally unreliable? In which case I would need to queue up the failed inserts locally and retry them until they eventually succeed?

    If anyone is interested, I have the debugview log that shows the pattern of insert failures.

    thanks, Tom

All Replies

  • Saturday, April 28, 2012 6:05 PM
     
     Answered

    After thinking about this last night, I realized that simple backoff-retry logic is totally insufficient. A more robust solution would be to execute update in a transaction, with some logic to determine whether the transaction succeeded.

                bool transOK = true;
                try
                {
                    using (TransactionScope tsc = new TransactionScope())
                    {
                        tableadaptor.Update(table);
                        tsc.Complete();
                    }
                }
                catch (TransactionAbortedException ex)
                {
                    Debug.WriteLine("TransactionAbortedException Message: {0}", ex.Message);
                    transOK = false;
                }

                if (transOK == true)
                {
                    table.Clear();
                }
                else
                {
                    //some retry logic
                }