title: Set TTL for DNS data for Amazon Aurora
body: <p>We're using Amazon Aurora (PostgreSQL) and we get some intermittent errors when trying to connect to the database:</p>
  
  <p><code>System.Net.Sockets.SocketException (0x80004005): This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server.</code></p>
  
  <p>But also:</p>
  
  <p><code>System.Exception: An error occurred while updating the entries. See the inner exception for details. ---&gt; System.Exception: An error occured while retrieving the InformationSchemaTable information. See the inner exception for details. ---&gt; System.Net.Sockets.SocketException: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server</code></p>
  
  <p>We're using <code>npgsql 3.2.5</code>. We receive these kind of errors intermittently both from a dedicated server running Windows Server 2016 and code hosted on Azure App Service. Hundreds of connections succeed, but some (a few per hour) fail with error messages like these. There is no significant load on the database when they occur, not an abnormal amount of connections (far from the limit).</p>
  
  <p>I found this in <a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.BestPractices.html" rel="nofollow noreferrer">Amazon Aurora Best Practices</a>:</p>
  
  <blockquote>
    <p>If your client application is caching the Domain Name Service (DNS) data of your DB instances, set a time-to-live (TTL) value of less than 30 seconds. Because the underlying IP address of a DB instance can change after a failover, caching the DNS data for an extended time can lead to connection failures if your application tries to connect to an IP address that no longer is in service.</p>
  </blockquote>
  
  <p>So my question is: How do I know if my client application is caching the DNS data? And is there a way to set the TTL for requests made by Npgsql, or does it have to be set somewhere general in .NET, or on the server?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>So after Shays answer, I took another look at it. It seems that we get two different kinds of errors, depending on hosting environment.</p>
  
  <p>Our code hosted on a dedicated server on premise get these kind of (DNS) errors:</p>
  
  <pre><code>System.Data.Entity.Core.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. ---&gt; System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---&gt; System.Net.Sockets.SocketException: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server
     at System.Net.Dns.GetAddrInfo(String name)
     at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
     at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
     at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
     at Npgsql.NpgsqlConnector.&lt;RawOpen&gt;d__139.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnector.&lt;Open&gt;d__136.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnection.&lt;Open&gt;d__28.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnection.Open()
     at Npgsql.NpgsqlServices.UsingPostgresDBConnection(NpgsqlConnection connection, Action`1 action)
     at Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection)
     at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
     --- End of inner exception stack trace ---
     at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
     at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
  ...
  </code></pre>
  
  <p>The same code, hosted in Azure App Services get the following (connection) error:</p>
  
  <pre><code>System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. ---&gt; Npgsql.NpgsqlException: Exception while reading from stream ---&gt; System.IO.IOException: Unable to read data from the transport connection: 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. ---&gt; System.Net.Sockets.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
     at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
     at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
     --- End of inner exception stack trace ---
     at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
     at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Npgsql.ReadBuffer.&lt;Ensure&gt;d__27.MoveNext()
     --- End of inner exception stack trace ---
     at Npgsql.ReadBuffer.&lt;Ensure&gt;d__27.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Npgsql.NpgsqlConnector.&lt;DoReadMessage&gt;d__148.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Npgsql.NpgsqlConnector.&lt;ReadPrependedMessages&gt;d__150.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnector.&lt;ReadMessage&gt;d__147.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnector.&lt;ReadExpecting&gt;d__154`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Npgsql.NpgsqlDataReader.&lt;NextResult&gt;d__32.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlDataReader.&lt;&lt;NextResultAsync&gt;b__31_0&gt;d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlCommand.&lt;Execute&gt;d__71.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlCommand.&lt;ExecuteDbDataReader&gt;d__92.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlCommand.&lt;&gt;c__DisplayClass90_0.&lt;&lt;ExecuteDbDataReaderAsync&gt;b__0&gt;d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.&lt;ExecuteAsync&gt;d__17.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.&lt;BufferlessMoveNext&gt;d__12.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlExecutionStrategy.&lt;ExecuteAsync&gt;d__7`2.MoveNext()
     --- End of inner exception stack trace ---
     at Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlExecutionStrategy.&lt;ExecuteAsync&gt;d__7`2.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.&lt;MoveNext&gt;d__11.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Linq.AsyncEnumerable.&lt;FirstOrDefault_&gt;d__165`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.TaskResultAsyncEnumerable`1.Enumerator.&lt;MoveNext&gt;d__3.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.&lt;MoveNextCore&gt;d__7.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Linq.AsyncEnumerable.AsyncIterator`1.&lt;MoveNext&gt;d__10.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.&lt;MoveNext&gt;d__5.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.&lt;ExecuteSingletonAsyncQuery&gt;d__21`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at OpenIddict.OpenIddictProvider`4.&lt;HandleTokenRequest&gt;d__25.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler.&lt;InvokeTokenEndpointAsync&gt;d__20.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler.&lt;HandleRequestAsync&gt;d__3.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.&lt;Invoke&gt;d__6.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.&lt;Invoke&gt;d__8.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.&lt;Invoke&gt;d__5.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.&lt;Invoke&gt;d__13.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.&lt;ProcessRequests&gt;d__188`1.MoveNext()
  </code></pre>
  
  <p>So maybe this is two problems that appeared at the same time. The Azure one (connection problem) started becoming more frequent after we took away <code>Keepalive=30</code> from the connection string, maybe we should put that back.</p>
  
  <p>The second problem might then be connection problems between our server supplier and the DNS server?</p>
  
  <p>Both problems are intermittent and only occurr a few times out of hundreds of connections.</p>