EF 6.1.3 - Devart leaking SafeHandles on slow Connections

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
hoekki
Posts: 8
Joined: Thu 21 Nov 2013 14:30

EF 6.1.3 - Devart leaking SafeHandles on slow Connections

Post by hoekki » Fri 26 Jan 2018 13:39

Hi guys,
I recently encountered a weird problem which resulted in an OutOfMemoryException within our application.
Context: For migrating data from one application version to another (and circumvent some issues with EF migrations), I basically dump all database contents to XML and import said data in the new version. This is done table by table, using a dedicated EF context for each table to be able to dispose the context from time to time.

So far so good, worked for about two years without problems. Now a client contacted me, complaining about OutOfMemory crashes when exporting. It took some time with manual tests and memory profiler to reproduce the issue. Apparently it takes a slow (or just bad) connection to an oracle server to cause the memory leak. With a fast connection, all works well. When using a MS SqlServer database, no issues.
Here a memory usage graph:
Image
The actual crash happened around the 2:05:00 mark where the private bytes peak at about 1.5 Gigabytes. I was not around for the crash because... well... 2 hours.

I ran the export again, just for half an hour, and took some snapshots to find the culprit. Here a screen shot showing loads of SafeCapiKeyHandles and SafeCspHandles:
Image
Instance Categorizer:
Image
And the instance list for SafeCapiKeyHandle:
Image
As you can see, there are just a few SafeHandles of generation 8, all the others are dependant on them but awaiting to be collected. When running the export for a longer time, there are always about 3-5 handles with increasing generation level, enmassing a huge amount of dependant handles.

In contrast when using a good connection, the SafeHandles look fine:
Image

I found a way to mitigate the issue short term, by inserting forced GarbageCollects on all generations in my code and enabling LargeAddressAware for the application. Here the SafeHandles in about the same amount of runtime:
Image
Still too many handles for my taste but at least they are kept within the lower 4-digits. This is keeping the actual problem manageable rather than solving it.

I can reproduce the issue with dotConnect for Oracle 9.2.187 and 9.4.348, accessing Oracle 12c Enterprise v12.1.0.2.0 on Unix server, client software running on Windows 7 Pro, Windows Server 2012 Enterprise, Windows 10 Pro, .Net Framework 4.5.2 and 4.6.
I am not sure if this issue is due to the slowness of the connection, package loss, connection encryption or something different entirely. But I am wondering if someone else has a similar problem and it would be much apreciated if you devart guys had a look at it. Sorry for the rather small amount of information, my resources to track this further are limited.

Best regards

Felix

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

Re: EF 6.1.3 - Devart leaking SafeHandles on slow Connections

Post by Shalex » Thu 01 Feb 2018 13:16

Thank you for the detailed description of the issue. We will investigate the question and notify you about the result.

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

Re: EF 6.1.3 - Devart leaking SafeHandles on slow Connections

Post by Shalex » Wed 14 Feb 2018 13:16

The investigation is in progress. Please tell us:

1) are you using Direct Mode or OCI Mode (via Oracle Client)?

2) if it is Direct Mode, are you setting any options via the DirectUtils class?
if it OCI Mode, specify the version of your Oracle Client

3) give us your connection string (roughly, without credentials)

hoekki
Posts: 8
Joined: Thu 21 Nov 2013 14:30

Re: EF 6.1.3 - Devart leaking SafeHandles on slow Connections

Post by hoekki » Fri 16 Feb 2018 09:10

Hi,
Thanks for the update.

1) I am using Direct Mode.

2) No, I am not using DirectUtils at all. Some settings on the OracleEntityProviderConfig though (ColumnTypeCasingConventionCompatibility, BatchUpdates, IgnoreSchemaName, DeleteDatabaseBehaviour, CaseInsensitiveComparison, CaseInsensitiveLike).

3) ConnectionString="User Id=***;Password=***;Server=***;Direct=True;Sid=***;Port=***", ProviderInvariant="Devart.Data.Oracle"
The connection string is not hardcoded in app.config or web.config, but generated using Devart.Data.Oracle.OracleConnectionStringBuilder.

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

Re: EF 6.1.3 - Devart leaking SafeHandles on slow Connections

Post by Shalex » Fri 16 Feb 2018 13:06

Thank you . We will notify you about the result of our investigation.

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

Re: EF 6.1.3 - Devart leaking SafeHandles on slow Connections

Post by Shalex » Wed 21 Feb 2018 19:21

We are investigating the issue. Please give us an additional information:

1) send us sqlnet.ora used by your Oracle 12c

2) try setting both DirectUtils.EncryptionLevel and DirectUtils.DataIntegrityLevel to SecurityLevel.Rejected. Does this make any difference?

3) is it possible to connect to a test database on your Oracle Server via internet? It would be great if we could reproduce the issue using some test application

Post Reply