Sometimes OCI invalid handle error

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
hegyesi
Posts: 6
Joined: Mon 07 Jan 2013 15:56

Sometimes OCI invalid handle error

Post by hegyesi » Wed 04 Dec 2019 16:45

Hello Support team,

We have got a web application which throws OCI invalid handle exceptions sometimes.

Message: OCI invalid handle.
Source: Devart.Data.Oracle
StackTrace: at Devart.Data.Oracle.bx.d(Int32 A_0)
at Devart.Data.Oracle.dw.b(Int32 A_0)
at Devart.Data.Oracle.OracleDataReader.Read()

Code:

Code: Select all

                        
                        OracleCommand mo_Command = new OracleCommand();
                        mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
                        mo_Command.CommandType = System.Data.CommandType.Text;
                        mo_Command.Connection = mo_Connection;
                        decimal mn_Sid = -1;
                        using (OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
                        {
                            using (OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
                            {
                                mo_Reader.Read();   //throws OCI invalid handle sometimes
                                mn_Sid = mo_Reader.GetDecimal(0);
                                mo_Reader.Close();
                            }
                        }
                        mo_ConnectionDescriptor.ConnectionSID = mn_Sid;
We use dotConnect for Oracle 9.9.867.0.

Do you have any idea what should I try to get rid of this exception?

Thanks in advance for your help.

Istvan

Shalex
Site Admin
Posts: 8939
Joined: Thu 14 Aug 2008 12:44

Re: Sometimes OCI invalid handle error

Post by Shalex » Fri 06 Dec 2019 13:23

Please give us additional information:

1) the version (xx.x) and capacity (x64 or x86) of your Oracle Client

2) the version (xx.x.x.x.x) and edition of your Oracle Server

3) your connection string (mark confidential information with asterisks)

4) run your code snippet in a for loop and specify the approximate number of iterations will be passed before throwing "OCI invalid handle"?

Code: Select all

    for (int i = 0; i < length; i++)
    {
        using (var mo_Connection = new OracleConnection(connectionString))
        {
            OracleCommand mo_Command = new OracleCommand();
            mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
            mo_Command.CommandType = System.Data.CommandType.Text;
            mo_Command.Connection = mo_Connection;
            decimal mn_Sid = -1;
            using (OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
            {
                using (OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
                {
                    mo_Reader.Read();   //throws OCI invalid handle sometimes
                    mn_Sid = mo_Reader.GetDecimal(0);
                    mo_Reader.Close();
                }
            }
        }
    }
    

hegyesi
Posts: 6
Joined: Mon 07 Jan 2013 15:56

Re: Sometimes OCI invalid handle error

Post by hegyesi » Tue 10 Dec 2019 16:34

Hi Shalex,

Thank you for your help.
Oracle client 32 bit and 11.2.0
Oracle server: 11g Release 11.2.0.3.0

I created a for loop for testing. Two times it threw exception after 74 cycle.

Exception:
Errors in file :
OCI-21500: internal error code, arguments: [KGHFRE3], [0x5982710], [], [], [], [], [], []


----- Call Stack Trace -----
calling call entry argument values in hex
location type point (? means dubious value)
-------------------- -------- -------------------- ----------------------------
_skgudmp()+100 CALLrel _kgdsdst() 489E68D 489ED14 53FC
_kgerin()+133 CALLreg 00000000 53FC 59FDF48
_kghnerror()+275 CALLrel _kgerin() 59FDF48 5A320C0 6EC97E7C 1 2
5982710
_kghfre()+4877 CALLrel _kghnerror() 59FDF48 5A05428 6EC97E7C
5982710 4 D0000035
_kpuhhfre()+1037 CALLrel _kghfre() 489EE00 0 6FDE3682 59FDF48
5A05428
_kpuxcStmCtxTerm()+ CALLrel _kpuhhfre() 59FD960 5982724 702B2E60
27
_kpufhndl0..0()+109 CALLrel _kpuxcStmCtxTerm() 5983108 832660 0 5983108
48 59FD960 1
_kpufhndl()+13 CALLrel _kpufhndl0..0() 2 A1C9EC 6FEFF8A2
_OCIHandleFree()+34 CALLptr 00000000 5983108 4
0564B2D9 CALLreg 00000000 5983108 4
05B65F7D CALLrel 05B654C0 2727D30 5983108 489FBD4
5B65E4D 2727D30 5983108
05B65E4A CALLreg 00000000 2727D30 5983108 489FBD4
2727D30 0 0
05B65944 CALLreg 00000000 1 0 0 489FBF0 2727AEC 2727E1C
05B671F8 CALLreg 00000000 DB1065 2727E1C 0 489FC38
A1C9EC 489FC84
60E7A2D1 CALLreg 00000000 489FC74 60F46C80 489FE38
60E7A27B CC210AC5 100
60E7A3D2 CALLrel 60E7A254 0 A1C9EC 2727E1C 0 0 2727E1C
60E7A10D CALLrel 60E7A338 2727E1C 7B9BA0 2727E1C
60E7A19B CC210B49 0
60E7A20A CALLrel 60E7A116 0 489FD27 489FE38 60E79C10 1
FFFFFF
60E79CB5 CALLrel 60E79D12 CC210B25 489FE38 60E79C10 0
3601C4 7BB110
60F4D95C CALLreg 00000000 489FE7C 7CFB20 489FE7C
489FE1C 60F4D9E9 CC21085D
60F4D9E4 CALLrel 60F4D920 CC21085D 60F41930 489FE7C 0 0
0
60F4D8D4 CALLrel 60F4D963 CC210831 60F41930 60E79C10 0
C8CAEAB0 60D9FE5C
60F41917 CALLrel 60F4D863 1 0 7B9BA0 0 60E79C10 489FE7C
60F419F8 CALLrel 60F418D1 CC210895 60F41930 0 7B33F0
CC210885 0
60F4A8B5 CALLreg 00000000 0 0 0 0 0 0
74F60417 CALLreg 00000000 7B33F0 74F60400 489FFD8
7781662D 7B33F0 85341342
7781662B CALLreg 00000000 7B33F0 85341342 0 0 7B33F0 0
778165F8 CALLrel 778165FE FFFFFFFF 778351D3 0 0
60F4A860 7B33F0
00000000 CALL??? 00000000

Call stack signature: 0x6e5b92cba08a3c05



call stack performance statistics:
total : 0.281000 sec
setup : 0.188000 sec
stack unwind : 0.000000 sec
symbol translation : 0.062000 sec
printing the call stack: 0.031000 sec
printing frame data : 0.000000 sec
printing argument data : 0.000000 sec


----- End of Call Stack Trace -----

75. kör: 103

Nem kezelt kivétel: System.AccessViolationException: Védett memória olvasására vagy írására történt kísérlet. Ez gyakran arra utal, hogy a memória más területe sérült.
a következő helyen: OciDynamicType.nativeOCIHandleFree(HandleRef , Int32 )
a következő helyen: OciDynamicType.OCIHandleFree(HandleRef , Int32 )
a következő helyen: Devart.Data.Oracle.dw.k()
a következő helyen: Devart.Data.Oracle.OracleDataReader.Close()
a következő helyen: Devart.Data.Oracle.OracleDataReader.Finalize()


Testing code:

Code: Select all

        
        static void Main(string[] args)
        {
            OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder();
            builder.Server = "fejleszt11n";
            builder.UserId = "pir2019_meo";
            builder.Password = "xxx";
            builder.Pooling = false;
            for (int i = 0; i < 300; i++)
            {
                OracleCommand mo_Command = new OracleCommand();
                mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
                mo_Command.CommandType = System.Data.CommandType.Text;
                using (OracleConnection mo_Connection = new OracleConnection(builder.ConnectionString))
                {
                    mo_Connection.Open();
                    mo_Command.Connection = mo_Connection;
                    decimal mn_Sid = -1;
                    using (OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
                    {
                        using (OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
                        {
                            mo_Reader.Read();
                            mn_Sid = mo_Reader.GetDecimal(0);
                            mo_Reader.Close();
                        }
                    }
                    mo_Connection.Close();
                    mo_Connection.Dispose();
                    Console.WriteLine($"{i+1}. kör: {mn_Sid}");
                }
            }
        }
        
I checked the same code with direct connection. I tried it lot of times without any exception.

Thank you for your help in advance.

Istvan

Shalex
Site Admin
Posts: 8939
Joined: Thu 14 Aug 2008 12:44

Re: Sometimes OCI invalid handle error

Post by Shalex » Thu 19 Dec 2019 15:16

We cannot reproduce the issue with Oracle Client 11.2.0.1.

1. Are you using instant client or full version of Oracle Client?

2. Check the properties of your \11.2.0\client_1\bin\oraclient11.dll and tell us its exact version (11.2.0.x).

pallaig2
Posts: 2
Joined: Thu 09 Apr 2020 14:53

Re: Sometimes OCI invalid handle error

Post by pallaig2 » Thu 09 Apr 2020 15:19

Hello Support team,

There is the same problem.

I tried different versions of DotConnect for Oracle:
- 8.5
- 9.5.399
- 9.5.483
- 9.6.675
- 9.7.734
- 9.8.838
- 9.9.867
- 9.10.909

Oracle client: 32 bit and 12.2.0.1
Oracle Server version: 11.2.0.3.0

The problem doesn’t always occur on the first run, but it usually occurs until the 5th.

Thanks for helping!

Testing code:

Code: Select all

static void Main(string[] args)
{
	string UserId = "xxx";
	string Password = "xxx";
	string Server = "xxx";
	bool IsDirect = false;

	Devart.Data.Oracle.OracleConnectionStringBuilder builder = new Devart.Data.Oracle.OracleConnectionStringBuilder();
	builder.UserId = UserId;
	builder.Password = Password;
	builder.Pooling = false;
	builder.Direct = IsDirect;
	builder.Server = Server;
	builder.ConnectionTimeout = 120;           

	for (int i = 0; i < 1000; i++)
	{
		try
		{
			Devart.Data.Oracle.OracleCommand mo_Command = new Devart.Data.Oracle.OracleCommand();
			mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
			mo_Command.CommandType = System.Data.CommandType.Text;
			using (Devart.Data.Oracle.OracleConnection mo_Connection = new Devart.Data.Oracle.OracleConnection(builder.ConnectionString))
			{
				mo_Connection.Open();
				mo_Command.Connection = mo_Connection;
				decimal mn_Sid = -1;
				using (Devart.Data.Oracle.OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
				{
					using (Devart.Data.Oracle.OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
					{
						mo_Reader.Read();
						mn_Sid = mo_Reader.GetDecimal(0);
						mo_Reader.Close();
					}
				}
				Console.WriteLine($"v1.1 - {i + 1}. round: {mn_Sid}");
				mo_Connection.Close();
			}
		}
		catch (Exception e)
		{
			Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error!!!!!!!!!!!!!!!!!" + e.Message);
		}
	}           
}

Shalex
Site Admin
Posts: 8939
Joined: Thu 14 Aug 2008 12:44

Re: Sometimes OCI invalid handle error

Post by Shalex » Fri 10 Apr 2020 18:07

@pallaig2

Your testing code works in our environment (10 successful runs).

1. Are you using an instant client or full version of Oracle Client?

2. Upgrade to v9.11.980. Does this help?

3. There are .NET Framework (shipped with installation) and .NET Standard (available via NuGet) provider assemblies. You are working with .NET Framework Devart.* assemblies, aren't you?

pallaig2
Posts: 2
Joined: Thu 09 Apr 2020 14:53

Re: Sometimes OCI invalid handle error

Post by pallaig2 » Wed 15 Apr 2020 08:23

I upgraded to v9.11.980 and it solved the problem.
Thanks for your help!

hegyesi
Posts: 6
Joined: Mon 07 Jan 2013 15:56

Re: Sometimes OCI invalid handle error

Post by hegyesi » Fri 05 Jun 2020 10:39

Hello Devart team,

After using for a month without error the v9.11.980 yesterday fired the OCI invalid handle error again. Please continue examining the problem.
It seems to me that it depends on the version of Oracle client. If I am using direct connection I can't reproduce the error. If I use the for cycle as I posted earlier and increment the number of cycles to 100000 it raises the exception on my side if I use Oracle 10 or 11 version of client.
Our clients said that they have the same issue on different databases, and clients.
Do you have any suggestion how to handle this kind of exception because it kills the application process and we need to restart tha web application in this situation.
It is now a critical issue on our side because the software is unreliable.
Is it ok for you if we create a test environment where you can check circumstances of the issue?

Thanks
Istvan

hegyesi
Posts: 6
Joined: Mon 07 Jan 2013 15:56

Re: Sometimes OCI invalid handle error

Post by hegyesi » Sun 07 Jun 2020 06:03

Please try to use the following c# method to reproduce the error:

Code: Select all

        public static void BugReproduce()
        {
            for (int i = 0; i < 1000000; i++)
            {
                OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder()
                {
                    Server = "server",
                    UserId = "userid",
                    Password = "password",
                    Direct = false,
                    Pooling = true
                };
                string mc_ConnectionString = builder.ConnectionString;

                using (Devart.Data.Oracle.OracleCommand mo_Command = new Devart.Data.Oracle.OracleCommand())
                {                   
                    mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
                    mo_Command.CommandType = System.Data.CommandType.Text;
                    using (Devart.Data.Oracle.OracleConnection mo_Connection = new Devart.Data.Oracle.OracleConnection(mc_ConnectionString))
                    {
                        mo_Connection.Open();
                        mo_Command.Connection = mo_Connection;
                        decimal mn_Sid = -1;
                        using (Devart.Data.Oracle.OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
                        {
                            using (Devart.Data.Oracle.OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
                            {
                                if (mo_Reader.Read())
                                {
                                    mn_Sid = mo_Reader.GetDecimal(0);
                                }
                                mo_Reader.Close(); 
                            }
                            mo_Cursor.Close();
                        }
                        string mc_Log = $"{i + 1}. cycle, Sid: {mn_Sid}, Conn: {mo_Connection.ConnectionString}, Home: {mo_Connection.Home}, ClientVersion: {OracleConnection.Homes[mo_Connection.Home]?.ClientVersion}";
                        Console.WriteLine(mc_Log);
                        mo_Connection.Commit();
                        mo_Connection.Close(); 
                    } 
                }   
            }
        }
The following exception excepted:
System.AccessViolationException was unhandled
Message: An unhandled exception of type 'System.AccessViolationException' occurred in Devart.Data.Oracle.dll
Additional information: Védett memória olvasására vagy írására történt kísérlet. Ez gyakran arra utal, hogy a memória más területe sérült.
Last sentence in english: Protected memory read or write attempt happened. It means the other part of memory is corrupted.

Please confirm that you can reproduce the error.

Thanks
Istvan

Shalex
Site Admin
Posts: 8939
Joined: Thu 14 Aug 2008 12:44

Re: Sometimes OCI invalid handle error

Post by Shalex » Mon 08 Jun 2020 16:52

We have reproduced the error and will notify you about the results of our investigation.

hegyesi
Posts: 6
Joined: Mon 07 Jan 2013 15:56

Re: Sometimes OCI invalid handle error

Post by hegyesi » Tue 09 Jun 2020 06:19

I am very happy that you could reproduced the error. I am waiting for the patch.

Istvan

hegyesi
Posts: 6
Joined: Mon 07 Jan 2013 15:56

Re: Sometimes OCI invalid handle error

Post by hegyesi » Sun 14 Jun 2020 06:35

Hi Devart team,

Do you have any update regarding this thread?

Thanks.
Istvan

Shalex
Site Admin
Posts: 8939
Joined: Thu 14 Aug 2008 12:44

Re: Sometimes OCI invalid handle error

Post by Shalex » Tue 30 Jun 2020 12:13

The investigation is in progress. As soon as we have any results, we will contact you.

Post Reply