1

With ASP.NET Core 2.2, Dapper Oracle 1.0.1 and managed Oracle ODP drivers 2.19.50 Using the following code to issue a simple read query. The code below is being called maybe ~10 times a minute by different API consumers.

// connectionString = Data Source=thehost:1521/blah;User Id=bob;Password=bob
using (IDbConnection dbConnection = new OracleConnection(this.connectionString))
{
    dbConnection.Open();
    var results = dbConnection.Query<MyDBModelClass>(myQuery);
    return results;
}

Most of the time the above works fine, but have been getting seemingly random .NET exceptions like the one below.

SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

OracleInternal.Network.ReaderStream.Read(OraBuf OB) NetworkException: ORA-12570: Network Session: Unexpected packet read error

OracleInternal.Network.ReaderStream.Read(OraBuf OB) OracleException:

ORA-12570: Network Session: Unexpected packet read error Oracle.ManagedDataAccess.Client.OracleException.HandleError(OracleTraceLevel level, OracleTraceTag tag, OracleTraceClassName className, OracleTraceFuncName funcName, Exception ex, OracleLogicalTransaction oracleLogicalTransaction)

After turning on tracing via OracleConfiguration.TraceLevel = 7 There are a lot of exceptions being logged from the driver that occur in these chunks:

(PRI) (EXT) Connection.connect()
(PRI) (ONS) (EXT) Connection.connect()
(PRI) (ONS) (EXT) ReceiverThread.establishConnection()
(PRI) (ONS) (ENT) Concurrency.setListFailed()
(PRI) (ONS) (EXT) Concurrency.setListFailed()
(PRI) (ONS) (ENT) ONS.nodeListFailOver()
(PRI) (ONS) (EXT) ONS.nodeListFailOver()
(PRI) (ONS) (ENT) ReceiverThread.establishConnection()
(PRI) (ONS) (ENT) Connection.connect()
(PRI) (ENT) Connection.connect()
(PRI) (ONS) (ERR) Connection.connect() (txnid=n/a) System.IO.IOException: The operation is not allowed on non-connected sockets.
   at System.Net.Sockets.NetworkStream..ctor(Socket socket, FileAccess access, Boolean ownsSocket)
   at OracleInternal.NotificationServices.Connection.connect()

The above exception led me to believe that I might not be creating/disposing/etc. the connection correctly since it looks like it's trying to read from a closed connection?

Is there anything in the code above that's obviously causing this?

O.O
  • 11,077
  • 18
  • 94
  • 182
  • You're handling the connection just fine, apart from an unnecessary call to open the connection (Dapper will automatically call open for you) but that's not a big deal. Is your network reliable? Does it suffer from packet loss? Have you tried doing an ICMP ping from your app server to your DB server and monitoring for packet loss? Or using Wireshark? Also, is connection pooling enabled or disabled on your connection string? – mason Oct 29 '19 at 17:16
  • @mason - it's a corporate network so should be, but I'll try it out and then update the question. Connection string is just like above, no settings other than the required defaults. – O.O Oct 29 '19 at 17:26

1 Answers1

0

This fixed the random errors that were happening. Not sure why though. Update the connection string to include a timeout, e.g. ;Connection Timeout=600

O.O
  • 11,077
  • 18
  • 94
  • 182