title: ODP.net managed driver throws ORA-12570: Network Session: Unexpected packet read error
body: <p>In one of our products we retrieve data from the Oracle database using stored procedures using the ODP.net managed driver.</p>
  
  <p>Every now and then (roughly every 1000 queries) we get the following exception:</p>
  
  <pre><code>(ORA-12570: Network Session: Unexpected packet read error)
  ---&gt; Oracle.ManagedDataAccess.Client.OracleException: ORA-12570: Network Session: Unexpected packet read error
  ---&gt; OracleInternal.Network.NetworkException: ORA-12570: Network Session: Unexpected packet read error
  ---&gt; 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&amp; 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[]&amp; defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData&amp; sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32&amp; noOfRowsFetched, Int64&amp; queryId, Int32 longFetchSize, Int32 initialLOBFetchSize, Int64[] scnFromExecution, Boolean&amp; bAllPureInputBinds, DataUnmarshaller&amp; dataUnmarshaller, MarshalBindParameterValueHelper&amp; marshalBindParamsHelper, Boolean bDefineDone, Boolean&amp; 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[]&amp; defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData&amp; sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32&amp; noOfRowsFetched, Int64&amp; queryId, Int32 longFetchSize, Int32 initialLOBFetchSize, Int64[] scnFromExecution, Boolean&amp; bAllPureInputBinds, DataUnmarshaller&amp; dataUnmarshaller, MarshalBindParameterValueHelper&amp; marshalBindParamsHelper, Boolean bDefineDone, Boolean&amp; bMoreThanOneRowAffectedByDmlWithRetClause)
     at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int32 lobPrefetchSize, OracleDependencyImpl orclDependencyImpl, Int64[]&amp; scnFromExecution, OracleParameterCollection&amp; bindByPositionParamColl, Boolean&amp; bBindParamPresent, Boolean isFromEF)
     at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
  </code></pre>
  
  <p>It seems like ODP.net is calling <a href="http://msdn.microsoft.com/en-us/library/ms145156(v=vs.110).aspx">System.Net.Sockets.Socket.Receive</a> with an invalid size parameter (&lt;=0 or greater than the length of buffer minus the value of the offset parameter).</p>
  
  <p>The exception cannot be reproduced manually and is never raised while executing different procedures with different parameters (ie it's random).</p>
  
  <p>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)</p>
  
  <p>Has anyone already experienced this issue? Are there any fixes available?</p>
  
  <p>Thanks in advance!</p>