Azure DocumentDB偶尔会抛出SocketException / GoneException [英] Azure DocumentDB sporadically throws SocketException / GoneException

查看:95
本文介绍了Azure DocumentDB偶尔会抛出SocketException / GoneException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新(2/8/17)



请参见下面的答案。



更新(2/7/17)



我发现重启可以让我成功运行网络应用从Visual Studio 2015,并多次击中该终结点。但是,当我停止应用程序并重新启动它时,它很可能会失败。然后它将反复失败,直到我重新启动计算机。重新启动VS'15还不够好。



一旦开始失败,从VS Code或dotnet.exe从命令行运行应用程序将表现出相同的行为。 / p>

原始帖子



我们已经建立了一个微服务系统,该系统调用DocumentDB来自几个API和Azure函数的集合。从API端,它间歇性地失败,并带有 SocketException (嵌套在其中的 GoneException )。据我们所知,鉴于它偶尔会起作用,因此调用它的代码大部分是正确的。 Azure函数可以正常工作。



为澄清起见:通过间歇性,我的意思是说它每天可能短暂工作一次或两次,然后输入在一天中的其余时间没有任何呼叫通过的情况下处于失败状态。这并不是每100个电话中有1个失败。这更像是1或2个成功调用后的不间断故障。



我能够通过编写一个简单的控制台应用程序来读取相同的异常,从而重新创建相同的异常。 DocumentDB并将结果打印到Debug输出。这将运行一两次,没有任何问题,然后每次都开始引发以下异常。有时它会执行几个小时,然后再进行两次调用,然后再次抛出。



虽然下面的测试器很原始,但主API充分利用了vNext项目结构。它使用单例DocumentClient进行连接(通过本机DI注入),并且从控制器到调用db的服务层几乎完全异步。我们使用一个单独的库来管理对DocumentDB的访问(如果不存在,则创建集合,添加扩展方法,简单的CRUD操作等),但是直接调用,如下所示,结果相同。



我注意到的一件事是,对于DocumentDB客户端的Core版本( Microsoft.Azure.DocumentDB.Core: 1.0。 0 ),而不是net46版本。由于其他库,我们的API需要4.6。



我可以在多台计算机,多个网络,多种连接类型上重新创建它。



问题:我们为什么会遇到此异常以及如何解决它?



天蓝色信息:




  • 美国东部2

  • 1000 RU / s

  • 标准等级

  • 会话一致性

  • 惰性索引策略:



    {
    indexingMode :惰性,
    自动:true,
    includedPaths:[{
    path: / *,
    indexes:[{
    kind: Range,
    dataType: Number,
    precision:-1
    },{
    kind:哈希,
    dataType:字符串,
    precision:3
    }]
    }],
    excludedPaths:[]
    }




测试类

  usi ng系统; 
使用System.Diagnostics;
使用System.Threading.Tasks;
使用Microsoft.Azure.Documents.Client;
使用Microsoft.Azure.Documents.Linq;
使用Newtonsoft.Json;

命名空间TestConnection
{
公共类程序
{
public static void Main(string [] args)
{
尝试
{
使用(var client = new DocumentClient(
new Uri( https://< our-docdb-name> .documents.azure.com:443 /),
我们的访问密钥,
新的ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
}))
{
var query = client.CreateDocumentQuery(UriFactory.CreateCollectionUri( Imports, User),
SELECT * FROM c where c.importId = \ 816d8e92-bd08-4705-9989 -09a0ece5892a\);
var docQuery = query.AsDocumentQuery();
GetResults(docQuery).Wait();
Debug.WriteLine( done);
}
}
catch(异常e)
{
Debug.WriteLine(e);
}
}

私有静态异步任务GetResults(IDocumentQuery< dynamic> docQuery)
{
Debug.WriteLine( getting);
var结果=等待docQuery.ExecuteNextAsync();
Debug.WriteLine(JsonConvert.SerializeObject(results));
}
}
}

project.json

  {
version: 1.0.0- *,
buildOptions:{
debugType:便携式,
emitEntryPoint:true
},
依赖关系:{
Microsoft.Azure.DocumentDB : 1.11.3
},
frameworks:{
net46:{}
}
}

例外

 'TestConnection.exe'(CLR v4.0.30319:DefaultDomain):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib .dll。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。 
'TestConnection.exe'(CLR v4.0.30319:DefaultDomain):已加载'C:\projects\TestConnection\src\TestConnection\bin\Debug\net46\win7-x64\ TestConnection.exe。符号已加载。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\projects\TestConnection\src\TestConnection\bin\Debug\net46\win7-x64 \Microsoft.Azure.Documents.Client.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089 \System.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0 .0__b77a5c561934e089\System.Core.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0 .0__b03f5f7f11d50a3a\System.Configuration.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4 .0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0 .0__b77a5c561934e089\System.Xml.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\projects\TestConnection\src\TestConnection\bin\Debug\net46\win7-x64 \Newtonsoft.Json.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
DocDBTrace信息:0:ID为1的DocumentClient初始化于端点:https://< our-docdb-name> .documents.azure.com /,其ConnectionMode:直接,连接协议:Tcp和一致性级别: null
获得
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\ \v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0 .0__b77a5c561934e089\System.Numerics.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4 .0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4 .0.0.0__b77a5c561934e089\System.Xml.Linq.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
'TestConnection.exe'(CLR v4.0.30319:TestConnection.exe):已加载'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0 .0__b77a5c561934e089\System.Data.dll'。跳过的加载符号。模块已优化,调试器选项仅我的代码已启用。
DocDBTrace信息:0:设置WriteEndpoint https://< our-docdb-name> -eastus2.documents.azure.com/ ReadEndpoint https://< our-docdb-name> -eastus2.documents。 azure.com/
DocDBTrace信息:0:将resourceName dbs / Imports / colls / User映射到resourceId u81pAO1OFwA =。 00000000-0000-0000-0000-000000000000
DocDBTrace信息:0:将resourceName dbs / Imports / colls / User映射到resourceId u81pAO1OFwA =。 ‘00000000-0000-0000-0000-000000000000’
线程0x3888已退出,代码为0(0x0)。
线程0x2c20已退出,代码为0(0x0)。
线程0x39fc已退出,代码为0(0x0)。
线程0x3610已退出,代码为0(0x0)。
线程0x3824已退出,代码为0(0x0)。
线程0x33d8已退出,代码为0(0x0)。
线程0x38d0已退出,代码为0(0x0)。
DocDBTrace信息:0:GetOpenConnection失败:RID:dbs / Imports / colls / User,ResourceType文档,Op:(operationType:查询,resourceType:Document),地址:rntbd://bn6prdddc05-docdb-1.documents .azure.com:18817 / apps / d54f0cf3-23d7-4050-9810-99d319d441a8 / services / d77a45f3-5611-4c1d-a08e-0f3ef60a31d9 / partitions / wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5 / replicas454: Microsoft.Azure.Documents.GoneException:消息:请求的资源在服务器上不再可用。
ActivityId:d71bc76d-1411-414d-a844-9f76a46ebcfd,请求URI:rntbd://bn6prdddc05-docdb-1.documents.azure.com:18817 / apps / d54f0cf3-23d7-4050-9810-99d319d441a8 / services / d77a45f3-5611-4c1d-a08e-0f3ef60a31d9 / partitions / wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5 / replicas / 131287308072454308s / --- System.Net.Sockets.SocketException:连接尝试失败,因为一段时间后连接方未正确响应,或者建立连接失败,因为连接的主机未能响应System.Net的13.68.28.135:18817
.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
在System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
在System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar,Func` 2 endFunction,Action`1 endAction,Task`1 promise,Boolean requiredSynchronization)
---从上一个引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter处。 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的ThrowForNonSuccess(任务任务)
,Microsoft.Azure.Documents.RntbdConnection。< OpenSocket> d__1c.MoveNext()的
- -内部异常堆栈跟踪的结尾--- Microsoft.Azur上的
e.Documents.RntbdConnection。< OpenSocket> d__1c.MoveNext()
-从上次引发异常的位置开始的堆栈跟踪--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess处的
(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在Microsoft.Azure.Documents.RntbdConnection。< Open> d__0.MoveNext()
- -从引发异常的先前位置结束的堆栈跟踪--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
,System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) )Microsoft.Azure.Documents.RntbdConnectionDispenser中的
。< OpenNewConnection> d__0.MoveNext()
---从上一个引发异常的位置开始的堆栈跟踪---
System.Runtime.CompilerServic中的.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
es.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)Microsoft.Azure.Documents.ConnectionPool中的
。< GetOpenConnection> d__0.MoveNext()
-从上次引发异常的位置开始的堆栈跟踪- -
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Azure.Documents.ConnectionPoolManager的
。< GetOpenConnection> d__0.MoveNext()
---从上一个引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)$ System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的b $ b Microsoft.Azure.Documents.RntbdTransportClient。< InvokeStoreAsync> d__0.MoveNext()
DocDBTrace信息:0:Microsoft异常.Azure.Documents.GoneException:消息:请求的资源在服务器上不再可用。
ActivityId:d71bc76d-1411-414d-a844-9f76a46ebcfd,请求URI:rntbd://bn6prdddc05-docdb-1.documents.azure.com:18817 / apps / d54f0cf3-23d7-4050-9810-99d319d441a8 / services / d77a45f3-5611-4c1d-a08e-0f3ef60a31d9 / partitions / wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5 / replicas / 131287308072454308s / --- System.Net.Sockets.SocketException:连接尝试失败,因为一段时间后连接方未正确响应,或者建立连接失败,因为连接的主机未能响应System.Net的13.68.28.135:18817
.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
在System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
在System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar,Func` 2 endFunction,Action`1 endAction,Task`1 promise,Boolean requiredSynchronization)
---从上一个引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter处。 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的ThrowForNonSuccess(任务任务)
,Microsoft.Azure.Documents.RntbdConnection。< OpenSocket> d__1c.MoveNext()的
- -内部异常堆栈跟踪的结尾--- Microsoft.Azur上的
e.Documents.RntbdConnection。< OpenSocket> d__1c.MoveNext()
-从上次引发异常的位置开始的堆栈跟踪--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess处的
(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在Microsoft.Azure.Documents.RntbdConnection。< Open> d__0.MoveNext()
- -从引发异常的先前位置结束的堆栈跟踪--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
,System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) )Microsoft.Azure.Documents.RntbdConnectionDispenser中的
。< OpenNewConnection> d__0.MoveNext()
---从上一个引发异常的位置开始的堆栈跟踪---
System.Runtime.CompilerServic中的.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
es.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)Microsoft.Azure.Documents.ConnectionPool中的
。< GetOpenConnection> d__0.MoveNext()
-从上次引发异常的位置开始的堆栈跟踪- -
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Azure.Documents.ConnectionPoolManager的
。< GetOpenConnection> d__0.MoveNext()
---从上一个引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)$ System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的b $ b Microsoft.Azure.Documents.RntbdTransportClient。< InvokeStoreAsync> d__0.MoveNext()
---堆栈结束跟踪从先前抛出异常的位置开始--- Syst中的
em.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在Microsoft.Azure.Documents.StoreReader。< CompleteActivity> d__1 MoveNext()
---从上一个引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime .CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)Microsoft.Azure.Documents.StoreReader中的
。在执行readMany
DocDBTrace警告时抛出了ReadMultipleReplicasInternalAsync> d__a.MoveNext()警告:0:接收到的异常,将重试,Microsoft.Azure.Documents.GoneException:消息:请求的资源在服务器上不再可用。
ActivityId:d71bc76d-1411-414d-a844-9f76a46ebcfd,请求URI:rntbd://bn6prdddc05-docdb-1.documents.azure.com:18817 / apps / d54f0cf3-23d7-4050-9810-99d319d441a8 / services / d77a45f3-5611-4c1d-a08e-0f3ef60a31d9 / partitions / wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5 / replicas / 131287308072454308s / --- System.Net.Sockets.SocketException:连接尝试失败,因为一段时间后连接方未正确响应,或者建立连接失败,因为连接的主机未能响应System.Net的13.68.28.135:18817
.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
在System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
在System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar,Func` 2 endFunction,Action`1 endAction,Task`1 promise,Boolean requiredSynchronization)
---从上一个引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter处。 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的ThrowForNonSuccess(任务任务)
,Microsoft.Azure.Documents.RntbdConnection。< OpenSocket> d__1c.MoveNext()的
- -内部异常堆栈跟踪的结尾--- Microsoft.Azur上的
e.Documents.StoreReader。< ReadMultipleReplicasInternalAsync> d__a.MoveNext()
-从上次引发异常的位置开始的堆栈结束跟踪--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess处的
(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在Microsoft.Azure.Documents.StoreReader。< ReadMultipleReplicaAsync> d__0.MoveNext()
- -从引发异常的先前位置结束的堆栈跟踪--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
,System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) )Microsoft.Azure.Documents.ConsistencyReader中的
。< ReadSessionAsync> d__8.MoveNext()
---从上一个引发异常的位置开始的堆栈跟踪---
.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在Sys tem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)位于Microsoft.Azure.Documents.ReplicatedResourceClient。< InvokeAsync> d__b.MoveNext()
-从先前位置开始的堆栈跟踪在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
处抛出了异常-System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Azure .Documents.ReplicatedResourceClient。<> c__DisplayClass1。< InvokeAsync> b__0> d__3.MoveNext()
---从上次引发异常的位置开始的堆栈跟踪---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Azure.Documents.BackoffRetryUtility`1处为
。<> c__DisplayClassf`1。<< ExecuteAsync> b__d> d__11.MoveNex t()
---从上一个引发异常的位置开始的堆栈跟踪---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime .CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)Microsoft.Azure.Documents.BackoffRetryUtility`1中的
。< ExecuteRetry> d__1b.MoveNext()
线程0x36e4退出,代码为0(0x0)。
线程0x3adc已退出,代码为0(0x0)。
线程0x3a68已退出,代码为0(0x0)。
线程0x18b0已退出,代码为0(0x0)。
...
/ *以上重复大约3次以上。* /
...
程序'[14648] TestConnection.exe'退出,代码为0( 0x0)。


解决方案

原来是我们的企业 Bitdefender导致此问题的Endpoint Security 。我们最初并不怀疑它,因为它清楚地记录了 dotnet.exe 已被列入白名单,并在我们运行该应用程序时允许其在适当的端口上进行通信。我们卸载了它,问题消失了。我们首先要研究到底是什么原因阻止了该问题,但至少我们知道这是一个临时解决方案,并且原始问题与代码无关。希望这对某人有帮助。


UPDATE (2/8/17):

See answer below.

UPDATE (2/7/17):

I've found that a restart can allow me to successfully run the web app from Visual Studio 2015, and hit the endpoint several times. However, when I stop the app and restart it, it will most likely fail. It will then fail repeatedly until I restart the computer. Restarting VS'15 is not good enough.

Once it begins to fail, running the app from VS Code or from command line with dotnet.exe exhibits the same behavior.

ORIGINAL POST:

We have a microservices system set up that calls a DocumentDB collection from a couple APIs and Azure Functions. It fails intermittently with a SocketException (GoneException nested within) from the API side. As far as we can tell, given that it works occasionally, the code to call it is mostly correct. The Azure Functions work without issue.

EDIT for clarification: by "intermittently," I mean it works briefly maybe once or twice a day, and then enters a fail state for the rest of the day where no calls go through. This isn't like 1 out of every 100 or so calls fail. This is more like nonstop failures after 1 or 2 successful calls.

I was able to recreate the same exception by writing a simple console app to read from the DocumentDB and print the results to the Debug output. This runs one or two times without any problem, then begins throwing the below exception every time. It will do this for sometimes a few hours before allowing a couple more calls through, then throwing again.

While the tester below is primitive, the main API takes full advantage of the vNext project structure. It uses a singleton DocumentClient to connect (injected via the native DI), and it's almost fully async from the controller down to the service layer that calls the db. We use a separate library to manage access to the DocumentDB (creating collections if they don't exist, adding extension methods, simple CRUD operations, etc.), but calling directly as shown below yields the same results.

One thing I've noticed is that it succeeds far more regularly for the Core version of the DocumentDB client ("Microsoft.Azure.DocumentDB.Core": "1.0.0") than it does for the net46 version. Our API needs 4.6 due to other libraries.

I could recreate this on multiple machines, multiple networks, multiple connection types.

Question: Why are we getting this exception and how do we fix it?

Azure information:

  • East US 2
  • 1000 RU/s
  • Standard tier
  • Session consistency
  • Lazy indexing policy:

    { "indexingMode": "lazy", "automatic": true, "includedPaths": [{ "path": "/*", "indexes": [{ "kind": "Range", "dataType": "Number", "precision": -1 },{ "kind": "Hash", "dataType": "String", "precision": 3 }] }], "excludedPaths": [] }

Test class

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using Newtonsoft.Json;

namespace TestConnection
{
    public class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                using (var client = new DocumentClient(
                    new Uri("https://<our-docdb-name>.documents.azure.com:443/"),
                    "our access key",
                    new ConnectionPolicy
                    {
                        ConnectionMode = ConnectionMode.Direct,
                        ConnectionProtocol = Protocol.Tcp
                    }))
                {
                    var query = client.CreateDocumentQuery(UriFactory.CreateCollectionUri("Imports", "User"),
                        "SELECT * FROM c where c.importId = \"816d8e92-bd08-4705-9989-09a0ece5892a\"");
                    var docQuery = query.AsDocumentQuery();
                    GetResults(docQuery).Wait();
                    Debug.WriteLine("done");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }

        private static async Task GetResults(IDocumentQuery<dynamic> docQuery)
        {
            Debug.WriteLine("getting");
            var results = await docQuery.ExecuteNextAsync();
            Debug.WriteLine(JsonConvert.SerializeObject(results));
        }
    }
}

project.json

{
    "version": "1.0.0-*",
    "buildOptions": {
        "debugType": "portable",
        "emitEntryPoint": true
    },
    "dependencies": {
        "Microsoft.Azure.DocumentDB": "1.11.3"
    },
    "frameworks": {
        "net46": {}
    }
}

Exception

'TestConnection.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\projects\TestConnection\src\TestConnection\bin\Debug\net46\win7-x64\TestConnection.exe'. Symbols loaded.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\projects\TestConnection\src\TestConnection\bin\Debug\net46\win7-x64\Microsoft.Azure.Documents.Client.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\projects\TestConnection\src\TestConnection\bin\Debug\net46\win7-x64\Newtonsoft.Json.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://<our-docdb-name>.documents.azure.com/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null
getting
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TestConnection.exe' (CLR v4.0.30319: TestConnection.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DocDBTrace Information: 0 : Set WriteEndpoint https://<our-docdb-name>-eastus2.documents.azure.com/ ReadEndpoint https://<our-docdb-name>-eastus2.documents.azure.com/
DocDBTrace Information: 0 : Mapped resourceName dbs/Imports/colls/User to resourceId u81pAO1OFwA=. '00000000-0000-0000-0000-000000000000'
DocDBTrace Information: 0 : Mapped resourceName dbs/Imports/colls/User to resourceId u81pAO1OFwA=. '00000000-0000-0000-0000-000000000000'
The thread 0x3888 has exited with code 0 (0x0).
The thread 0x2c20 has exited with code 0 (0x0).
The thread 0x39fc has exited with code 0 (0x0).
The thread 0x3610 has exited with code 0 (0x0).
The thread 0x3824 has exited with code 0 (0x0).
The thread 0x33d8 has exited with code 0 (0x0).
The thread 0x38d0 has exited with code 0 (0x0).
DocDBTrace Information: 0 : GetOpenConnection failed: RID: dbs/Imports/colls/User, ResourceType Document, Op: (operationType: Query, resourceType: Document), Address: rntbd://bn6prdddc05-docdb-1.documents.azure.com:18817/apps/d54f0cf3-23d7-4050-9810-99d319d441a8/services/d77a45f3-5611-4c1d-a08e-0f3ef60a31d9/partitions/wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5/replicas/131287308072454308s/, Exception: Microsoft.Azure.Documents.GoneException: Message: The requested resource is no longer available at the server.
ActivityId: d71bc76d-1411-414d-a844-9f76a46ebcfd, Request URI: rntbd://bn6prdddc05-docdb-1.documents.azure.com:18817/apps/d54f0cf3-23d7-4050-9810-99d319d441a8/services/d77a45f3-5611-4c1d-a08e-0f3ef60a31d9/partitions/wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5/replicas/131287308072454308s/ ---> 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 13.68.28.135:18817
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdConnection.<OpenSocket>d__1c.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Documents.RntbdConnection.<OpenSocket>d__1c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdConnection.<Open>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdConnectionDispenser.<OpenNewConnection>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ConnectionPool.<GetOpenConnection>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ConnectionPoolManager.<GetOpenConnection>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdTransportClient.<InvokeStoreAsync>d__0.MoveNext()
DocDBTrace Information: 0 : Exception Microsoft.Azure.Documents.GoneException: Message: The requested resource is no longer available at the server.
ActivityId: d71bc76d-1411-414d-a844-9f76a46ebcfd, Request URI: rntbd://bn6prdddc05-docdb-1.documents.azure.com:18817/apps/d54f0cf3-23d7-4050-9810-99d319d441a8/services/d77a45f3-5611-4c1d-a08e-0f3ef60a31d9/partitions/wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5/replicas/131287308072454308s/ ---> 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 13.68.28.135:18817
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdConnection.<OpenSocket>d__1c.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Documents.RntbdConnection.<OpenSocket>d__1c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdConnection.<Open>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdConnectionDispenser.<OpenNewConnection>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ConnectionPool.<GetOpenConnection>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ConnectionPoolManager.<GetOpenConnection>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdTransportClient.<InvokeStoreAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.StoreReader.<CompleteActivity>d__1f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.StoreReader.<ReadMultipleReplicasInternalAsync>d__a.MoveNext() is thrown while doing readMany
DocDBTrace Warning: 0 : Received gone exception, will retry, Microsoft.Azure.Documents.GoneException: Message: The requested resource is no longer available at the server.
ActivityId: d71bc76d-1411-414d-a844-9f76a46ebcfd, Request URI: rntbd://bn6prdddc05-docdb-1.documents.azure.com:18817/apps/d54f0cf3-23d7-4050-9810-99d319d441a8/services/d77a45f3-5611-4c1d-a08e-0f3ef60a31d9/partitions/wkjhgkwj-c85a-4b08-b026-6bc8010b1bb5/replicas/131287308072454308s/ ---> 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 13.68.28.135:18817
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.RntbdConnection.<OpenSocket>d__1c.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Documents.StoreReader.<ReadMultipleReplicasInternalAsync>d__a.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.StoreReader.<ReadMultipleReplicaAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ConsistencyReader.<ReadSessionAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<InvokeAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<>c__DisplayClass1.<<InvokeAsync>b__0>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClassf`1.<<ExecuteAsync>b__d>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext()
The thread 0x36e4 has exited with code 0 (0x0).
The thread 0x3adc has exited with code 0 (0x0).
The thread 0x3a68 has exited with code 0 (0x0).
The thread 0x18b0 has exited with code 0 (0x0).
...
/* The above repeats about 3 more times.*/
...
The program '[14648] TestConnection.exe' has exited with code 0 (0x0).

解决方案

It turned out to be our enterprise Bitdefender Endpoint Security causing the issue. We initially didn't suspect it, since it pretty clearly logged that dotnet.exe was whitelisted and allowed to communicate on the appropriate ports whenever we ran the app. We uninstalled it and the issue went away. We're looking into what exactly it blocked to cause the issue in the first place, but at least we know there's a temporary solution and that the original problem wasn't code-related. Hope this helps someone.

这篇关于Azure DocumentDB偶尔会抛出SocketException / GoneException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆