19

In one of our products we retrieve data from the Oracle database using stored procedures using the ODP.net managed driver.

Every now and then (roughly every 1000 queries) we get the following exception:

(ORA-12570: Network Session: Unexpected packet read error)
---> Oracle.ManagedDataAccess.Client.OracleException: ORA-12570: Network Session: Unexpected packet read error
---> OracleInternal.Network.NetworkException: ORA-12570: Network Session: Unexpected packet read error
---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: size
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
   at OracleInternal.Network.ReaderStream.ReadIt(OraBuf OB, Int32 len)
   --- End of inner exception stack trace ---
   at OracleInternal.Network.ReaderStream.ReadIt(OraBuf OB, Int32 len)
   at OracleInternal.Network.ReaderStream.WaitForReset()
   at OracleInternal.Network.OracleCommunication.Reset()
   at OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int32 initialLOBFetchSize, Int64[] scnFromExecution, Boolean& bAllPureInputBinds, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Boolean bDefineDone, Boolean& bMoreThanOneRowAffectedByDmlWithRetClause)
   --- End of inner exception stack trace ---
   at Oracle.ManagedDataAccess.Client.OracleException.HandleError(OracleTraceLevel level, OracleTraceTag tag, Exception ex)
   at OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int32 initialLOBFetchSize, Int64[] scnFromExecution, Boolean& bAllPureInputBinds, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Boolean bDefineDone, Boolean& bMoreThanOneRowAffectedByDmlWithRetClause)
   at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int32 lobPrefetchSize, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Boolean isFromEF)
   at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()

It seems like ODP.net is calling System.Net.Sockets.Socket.Receive with an invalid size parameter (<=0 or greater than the length of buffer minus the value of the offset parameter).

The exception cannot be reproduced manually and is never raised while executing different procedures with different parameters (ie it's random).

Configuration: ODP.net managed driver version: 4.121.1.0 .net framework 4.5 Oracle server version: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 (Linux)

Has anyone already experienced this issue? Are there any fixes available?

Thanks in advance!

vc 74
  • 37,131
  • 7
  • 73
  • 89
  • 1
    ever had any solution for this @vc_74 – Pierluc SS Oct 15 '15 at 15:02
  • It's not your situation, but the same error will happen when trying to use the Oracle pure managed driver when connecting to server that requires advanced encryption (http://stackoverflow.com/a/34227815/12597) – Ian Boyd Dec 11 '15 at 17:48
  • Hi, did you managed how to fix this? Thanks – Edgar Feb 11 '16 at 20:41
  • @EdgarRochaCarvalho Yes, but it took a while... (see answer below) – vc 74 Mar 14 '16 at 16:11
  • @PierlucSS Please see answer below – vc 74 Mar 14 '16 at 16:11
  • @vc74 Thanks. Since I found others bugs I just stopped using this library for now ( http://stackoverflow.com/questions/35352060/odp-net-oracle-manageddataacess-random-ora-12570-errors ) – Edgar Mar 14 '16 at 17:58
  • Possible duplicate: http://stackoverflow.com/questions/35352060/odp-net-oracle-manageddataacess-random-ora-12570-errors – vapcguy Oct 19 '16 at 19:26

2 Answers2

5

After opening a ticket with the Oracle support, they sent an unofficial updated version of the managed ODP.net library which seems to fix the issue.

Hopefully the fix should be part of the next ODAC release (the latest available today is from Oct 2015).

If you see this error in your application, it's probably due to the same bug in the managed ODP.net library, not the way you use it.

Another thing to consider is if something in the network infrastructure could interrupt idle tcp/ip connections during the execution of long requests as described in this SO answer.

vc 74
  • 37,131
  • 7
  • 73
  • 89
  • 1
    I hope they fixed two other bugs, pooling management and clob bytearray errors. ( http://stackoverflow.com/questions/35352060/odp-net-oracle-manageddataacess-random-ora-12570-errors ). I will try again on next official release. – Edgar Mar 14 '16 at 18:02
  • @EdgarRochaCarvalho What's annoying is that they don't seem to pay much attention to the messages posted on their forums, if you don't have a support account, the only thing you can do is wait for an update – vc 74 Mar 14 '16 at 18:04
  • 4
    Oracle.ManagedDataAccess from nuget: 12.1.24160419 - same problem. – VikciaR Aug 04 '16 at 14:15
  • Same problem with 12c ODP .NET client, Product Version 4.121.2.20150926 ODAC RELEASE 4. And it happened to me randomly for the first time after 4 months of debugging just fine. It went to my `catch`, and then continued to the next function call. I backed up my debug cursor to re-run my DB updating function that had the exception, and then it went through just fine without the error. Maybe the solution is to just have a routine that checks for the error and re-runs the DB update function if it finds it? – vapcguy Oct 19 '16 at 13:21
  • Actually, did some more research. Seems like this question might actually be a duplicate: http://stackoverflow.com/questions/35352060/odp-net-oracle-manageddataacess-random-ora-12570-errors – vapcguy Oct 19 '16 at 19:26
  • I had to upgrade to Oracle.ManagedDataAccess to 12.2.100 to get rid of this issue. I was also sitting at 12.1 – Klaus Nji Jun 13 '18 at 18:51
  • 3
    I am still seeing the issue in Oracle.ManagedDataAccess version 19.6.0 – iCode Apr 15 '20 at 12:48
  • @iCode Is it possible that something drops inactive tcp/ip connections in your network infrastructure? – vc 74 Apr 15 '20 at 13:38
  • @vc74 That's a great question. Something that I'll look into. Thank you. – iCode Apr 15 '20 at 13:40
2

After reading through a similar question at ODP.NET Oracle.ManagedDataAcess random ORA-12570 errors, it seems like it's actually a pooling problem. Apparently the answer is to either set Pooling=false in the Connection String, or to find out just how many threads can be opened and how long the connection can be open before it becomes too much for Oracle to handle. This was the answer the author of that question posted:

To find the best configuration with pooling enabled I created a test application to start 50 threads (each one doing 1 test each 50ms), and decreased the default pool values until the error stoped. This way I was able to get an optimal configuration, stable, without any errors.

Obviously it does not applies to every server, but this is my final connection string configuration:

Pooling=true;Min Pool Size=1;Connection Lifetime=180;Max Pool Size=50;Incr Pool Size=5

Community
  • 1
  • 1
vapcguy
  • 7,097
  • 1
  • 56
  • 52
  • This splution or disabling pooling doesn't solve it. It seems like the problem is the one explained by Vc 74 – Gultekin Jan 22 '19 at 12:27
  • @Gultekin Not true at all. I've used `Pooling=false` plenty of times and it works. As I also said, you can experiment with the `Min Pool Size` & `Max Pool Size` and set how long you want to keep it alive with the `Connection Lifetime` and how it should be stepped up via the `Incr Pool Size`, if you want to set it, instead. I offered BOTH solutions, here. +I tried updating the ODP.net library like vc 74 said & I had the same issue until I made the adjustments I described here in my answer. Why would I have wasted my time if the solution were already here? Maybe it solves it for some-but not me. – vapcguy Jan 25 '23 at 19:19