使用sdn4时为什么NoHttpResponseException占用

时间:2016-01-05 07:18:33

标签: neo4j spring-data-neo4j spring-data-neo4j-4

我们使用sdn4访问neo4j,但有时会发生此异常。是什么原因? neo4j的2.2.5版。我们可以配置什么配置以避免这种异常?

  at org.neo4j.ogm.session.request.DefaultRequest.execute(DefaultRequest.java:105) ~[neo4j-ogm-1.1.4-20151201.162656-1.jar:na]
at org.neo4j.ogm.session.request.SessionRequestHandler.execute(SessionRequestHandler.java:99) ~[neo4j-ogm-1.1.4-20151201.162656-1.jar:na]
at org.neo4j.ogm.session.request.SessionRequestHandler.execute(SessionRequestHandler.java:64) ~[neo4j-ogm-1.1.4-20151201.162656-1.jar:na]
at org.springframework.data.neo4j.repository.query.QueryResultGraphRepositoryQuery$1.apply(QueryResultGraphRepositoryQuery.java:65) ~[spring-data-neo4j-4.0.0.RELEASE.jar:na]
at org.springframework.data.neo4j.repository.query.QueryResultGraphRepositoryQuery$1.apply(QueryResultGraphRepositoryQuery.java:62) ~[spring-data-neo4j-4.0.0.RELEASE.jar:na]
at org.neo4j.ogm.session.delegates.TransactionsDelegate.doInTransaction(TransactionsDelegate.java:54) ~[neo4j-ogm-1.1.4-20151201.162656-1.jar:na]
at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:422) ~[neo4j-ogm-1.1.4-20151201.162656-1.jar:na]
at org.springframework.data.neo4j.repository.query.QueryResultGraphRepositoryQuery.mapToConcreteType(QueryResultGraphRepositoryQuery.java:62) ~[spring-data-neo4j-4.0.0.RELEASE.jar:na]
at org.springframework.data.neo4j.repository.query.QueryResultGraphRepositoryQuery.execute(QueryResultGraphRepositoryQuery.java:52) ~[spring-data-neo4j-4.0.0.RELEASE.jar:na]
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:50) ~[spring-data-neo4j-4.0.0.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:454) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:432) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
Caused by: org.apache.http.NoHttpResponseException: 10.171.23.230:7475 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261) ~[httpcore-4.4.1.jar:4.4.1]
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165) ~[httpcore-4.4.1.jar:4.4.1]
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272) ~[httpcore-4.4.1.jar:4.4.1]
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124) ~[httpcore-4.4.1.jar:4.4.1]
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.4.1.jar:4.4.1]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) ~[httpclient-4.4.1.jar:4.4.1]
at org.neo4j.ogm.session.request.DefaultRequest.execute(DefaultRequest.java:80) ~[neo4j-ogm-1.1.4-20151201.162656-1.jar:na]
... 56 common frames omitted

2 个答案:

答案 0 :(得分:1)

由于长时间不活动,服务器可能已关闭连接。 Apache HttpClient documentation说明了这一点:

  

2.6。连接保持活动策略HTTP规范没有指定持久连接可以保留多长时间   活。某些HTTP服务器使用非标准的Keep-Alive标头   与客户沟通他们打算以秒为单位的时间段   保持服务器端的连接活动。 HttpClient使用   此信息(如果有)。如果Keep-Alive标头不存在   在响应中,HttpClient假设连接可以保持活动状态   无限期。但是,通常使用的许多HTTP服务器都已配置   在一段时间不活动后删除持久连接   为了节省系统资源,经常没有通知   客户端

通常,会检测到重新使用陈旧连接,但this answer表明在某些情况下,过时连接上的写入请求似乎成功。在这种情况下,缺少有效的响应将产生org.apache.http.NoHttpResponseException

SDN目前没有任何机制来缓解此问题,我不知道 neo4j-server.properties 中的任何设置,以防止在服务器端出现此行为。

答案 1 :(得分:0)

OGM的最新快照版本1.1.5-SNAPSHOT在抛出NoHttpResponseException的情况下启用了请求重试策略:https://github.com/neo4j/neo4j-ogm

重试策略配置为在初始失败后再次尝试请求3次,每次尝试之间延迟2秒。

此策略的基本原理基于Apache HttpClient文档,该文档说明了以下内容:

  

在某些情况下,通常在负载较重时,Web服务器可能能够接收请求但无法处理它们。缺乏足够的资源,如工作线程就是一个很好的例子。这可能导致服务器在不给出任何响应的情况下断开与客户端的连接。遇到这种情况时,HttpClient会抛出NoHttpResponseException。在大多数情况下,使用NoHttpResponseException重试失败的方法是安全的。   http://hc.apache.org/httpclient-3.x/exception-handling.html

OGM的1.1.5-SNAPSHOT版本与SDN 4.0兼容。

OGM用户

如果您使用的是“独立”OGM,则需要将此依赖项添加到您的pom中:

<repository>
    <id>neo4j-snapshots</id>
    <url>http://m2.neo4j.org/content/repositories/snapshots</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

SDN用户

所需的依赖项应该已经包含在最新的Spring Data Neo4j 4.0.0-SNAPSHOT版本中。您需要在pom中使用以下存储库才能使用SDN 4.0的快照构建

<repository>
    <id>spring-libs-snapshot</id>
    <url>http://repo.spring.io/libs-snapshot</url>
</repository>