0

While an app tries to connect to database server and retrieve some data, it sometimes raise an exception and it seems like it leaves dead threads when expcetion raised even when it's handled. So there are about 300 threads that getting service down.

Here is code invoked periodically on timer:

Parallel.ForEach(dbs, pair =>
        {
            db l = pair.Value;

            if (String.IsNullOrEmpty(l.city))
                l.city = l.configCity;

            using (OracleConnection conn = new OracleConnection(l.connString))
            {
                try
                {                        
                    conn.Open();
                }
                catch (Exception exc)
                {
                    Console.WriteLine(String.Format("({0}, {1}): {2}{3}", l.connAlias, l.lid, exc.Message, Environment.NewLine));                        
                }

                try
                {
                    if ((conn != null) && (conn.State == ConnectionState.Open))
                    {        
                        // This method just call stored procedure and then set received data to 'l' object                    
                        if (!DbConnection.SetBadicData(conn, ref l))
                        {
                            Console.WriteLine(String.Format("Couldn't refresh basic data on ({0}, {1})", l.connAlias, l.id));
                        }                            

                        // This method also just call procedure and set received data to object
                        if (!DbConnection.SetExtendedData(conn, ref l))
                        {
                            Console.WriteLine(String.Format("Couldn't refresh advanced data on ({0}, {1})", l.connAlias, l.lid));
                        }
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(String.Format("({0}, {1}): {2}{3}", l.connAlias, l.lid, exc.Message, Environment.NewLine));
                }
            }

        });

Exceptions are:

  • Attempted to read or write protected memory. This is often an indication that other memory is corrupt
  • Internal exception in Oracle client
  • SEHException - External component has thrown an exception

Component that used to connect to database is devArt dotConnect for Oracle.

How can I manage it guys? Does BeginConnect and then forced breaking by EndConnect will help?

kseen
  • 359
  • 8
  • 56
  • 104
  • 2
    The devArt support may be a better place for this question. – M.Babcock Feb 17 '12 at 03:47
  • Or post a link to this question in their support forum along with a short description of the problem. – Eric J. Feb 17 '12 at 03:59
  • Why are you squashing this exception? catch (Exception exc) { Console.WriteLine(String.Format("({0}, {1}): {2}{3}", l.connAlias, l.lid, exc.Message, Environment.NewLine)); } – Nick Ryan Feb 17 '12 at 16:08
  • @NickRyan What special can I do with this exception? – kseen Feb 20 '12 at 03:03
  • What I meant was, if you weren't able to open the connection, why are you not throwing the error up the stack? You aren't actually handling the error - all you are doing is logging it. Should you even attempt the next try catch block if the first try errored out? Anyway, as @M.Babcock said, you are probably best taking this up on the devart forum. – Nick Ryan Feb 20 '12 at 10:07
  • @NickRyan How can I handle the error in the first block? What should I do if it couldn't open the connection? – kseen Feb 20 '12 at 10:31

1 Answers1

1

Get a fixed library :-)

But seriously. If you have a third party library that you have to use, cannot change it and which is buggy, the only way I see is to run it in a separate AppDomain. Communication between domains is more difficult than just calling a method but still relatively easy. You can for example use a WCF service (with named pipe) to communicate.

Once you have your code handling nasty library in a separate AppDomain, you can recycle (destroy and recreate) that domain periodically or under other conditions. That will kill off all hanging threads, unreleased objects etc.

It is a workaround type of solution but it should give you at least a way out of this.

Maciej
  • 7,871
  • 1
  • 31
  • 36