oracle / dotnet-db-samples

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

Memory issues after upgrading to 3.21.90 #281

Closed nimsilva closed 1 year ago

nimsilva commented 1 year ago

We have recently upgraded Oracle.ManagedDataAccess from 3.21.1 to 3.21.90

Since then we have incurred into a memory issue in our application, this leads to memory exhaustion and causes a crash in the container we are running in.

We are using dotMemory Profiler to look at the memory used by the application.

We have found that when using the package version 3.21.90 the memory of the application climbs up with every request it serves. We have isolated the problematic piece of code to be connection.Open(). Every time connection.Open() is called the memory in Heap generation 0 climbs up. When garbage collector kicks in, the memory in the Heap generation 0 is cleaned but the Unmanaged memory grows by almost the same proportion, this unmanaged memory continues to grow in the same manner and is never cleaned.

By downgrading back to package version 3.21.1 with the exact same code, we have experienced that when garbage collector kicks in the same happens, the memory in Heap generation 0 is cleaned out and Unmanaged memory grows by almost the same proportion, however the unmanaged memory is then slowly disposed off as the application continues to run while in version 3.21.90 the unmanaged memory just continues to grow.

With the same code and same requests with version 3.21.90 we can quickly go into 1GB of memory used while with version 3.21.1 we never go past 300MB.

We have tested with other versions of the package, we only start seeing the issue from version 3.21.80+

Right now our fix is to downgrade to version 3.21.70 of the package.

alexkeh commented 1 year ago

For memory leak issues, please open an Oracle Support service request so that the source of the memory leak can be diagnosed. A lot happens during a connection Open(). It can be very hard to diagnose without access to the memory profiling reports, traces, and .NET code.

One thing to verify is that your .NET code is closing/disposing your OracleConnection objects explicitly or that you are using the using the using statement, which calls Dispose() at the end.

nimsilva commented 1 year ago

We are using the using statement. Like I mentioned in the issue we are running the exact same code but only experience the memory leak on version 3.21.80 and 3.21.90 of the package. Downgrading to version 3.21.70 was the fix.

I will close this issue and contact Oracle Support like you mentioned. Thank you 😊

daniel-liuzzi commented 1 year ago

UPDATE: I spoke too soon; see next comment

We hit the exact same scenario as the OP, updating from 3.21.70 to 3.21.90 resulted in memory usage skyrocketing. We have since updated to 3.21.100 (released 5 days after this issue was reported) and the memory leak seems to be resolved.

daniel-liuzzi commented 1 year ago

Today we detected 3.21.100 suffers from the same memory leak problem. This issue should be reopened.

alexkeh commented 1 year ago

Milestone removed since problem is reported as it still exists.

nimsilva commented 1 year ago

We tested version 3.21.100 locally on our solution and it seems that the memory issue we had with the version 3.21.80 and 3.21.90 was resolved. We will deploy this to a live environment soon and monitor further.

alexkeh commented 1 year ago

OP reports ODP.NET 21.10 resolves the problem.