oracle / dotnet-db-samples

.NET code samples for Oracle database developers #OracleDotNet
http://otn.oracle.com/dotnet
MIT License
413 stars 191 forks source link

Opening connections in parallel without pooling throws NullReferenceException in 3.21.80+ #278

Closed alitas closed 11 months ago

alitas commented 1 year ago

Upon upgrading from 3.21.70 to 3.21.90, we started to get NullReferenceException sporadically when opening a new connection. This happens once every 5-10K connection attempts, so it feels like a timing issue when opening connections. For reference, pooling is disabled in these connections. Confirmed that the same issue appears in 3.21.80 but not 3.21.70.

Example code for reproduction:

Parallel.ForEach(Enumerable.Range(0, 10_000),
        i =>
        {
                using var oracleConnection = new OracleConnection(connectionString);
                oracleConnection.Open();
        });

Trace logs: OracleNRE.log

alitas commented 1 year ago

The issue is still reproducable in 3.21.100 with the stack trace:

 System.NullReferenceException: Object reference not set to an instance of an object.
   at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
   at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
   at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)
   at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
alitas commented 1 year ago

I believe the serviceName can be null at times, and calling pr.ServiceName.Equals or pr.ServiceName.ToLower causes these exceptions.

alexkeh commented 1 year ago

The Oracle .NET team believes it has reproduced this problem (or something very similar). A bug number will be forthcoming.

alexkeh commented 1 year ago

Bug number is 35528243.

alexkeh commented 11 months ago

The test case for Bug 35528243 was tested with code that was to be shipped for 21.12. The bug did not reproduce with that label event though we were able to reproduce this bug before with an ODP.NET label in June. What likely happened was that another related bug fix also fixed this bug.

Closing for now. Let us know if the problem re-occurs in your particular use case and I will re-open.