由于SSL连接已经关闭,如何解决Droping Close的错误 [英] How to fix the Dropping Close since the SSL connection is already closing error in spray

查看:151
本文介绍了由于SSL连接已经关闭,如何解决Droping Close的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用API,但是大多数时候我总是收到错误消息: 由于SSL连接已经关闭,正在关闭过早关闭 (服务器似乎不支持请求管道)。像90%的时间一样,我得到了该错误,这意味着:在极少数情况下,查询确实会返回它应该返回的数据。

I’m making a call to an API, but most of the time I keep getting an error: "Dropping Close since the SSL connection is already closing" and "Premature connection close (the server doesn't appear to support request pipelining)." Like 90% of the time I get that error, meaning: on very rare occasions the query does return the data it supposed to.

要确保此错误不是API的服务器问题,我使用Node.js(Express和Request库)复制相同的查询,并且每次都可以使用。

To make sure this wasn’t the API’s server issue, I replicate the same query using Node.js (Express and Request libs) and it works every time. It makes me almost sure is a spray bug.

以下是代码示例

case class MyClass(user: String, pass: String)

class MyActor extends Actor {
  import spray.client.pipelining._
  import spray.http.BasicHttpCredentials
  import spray.http.{HttpRequest,HttpResponse}
  import scala.concurrent.Future

  import context.dispatcher

  def receive = {
    case myClass: MyClass => {
      val credentials: BasicHttpCredentials = BasicHttpCredentials(myClass.user, myClass.pass)
      val url: String = "https://myApi?params=values"
      val request: HttpRequest = Get(url) ~> addCredentials(credentials)
      val pipeline = sendReceive
      val response: Future[HttpResponse] = pipeline(request)
      val finalRes: Future[String] = response.map{ r =>
        println(r)
        r.entity.asString
      }
      finalRes pipeTo sender
    }
  } // end receive
} //end Actor

错误详细信息

04/01 10:19:05 DEBUG[on-spray-can-akka.actor.default-dispatcher-8] a.i.TcpOutgoingConnection - Attempting connection to ...
04/01 10:19:05 DEBUG[on-spray-can-akka.actor.default-dispatcher-6] a.i.TcpOutgoingConnection - Connection established to ...
04/01 10:19:05 DEBUG[on-spray-can-akka.actor.default-dispatcher-6] s.c.c.HttpClientConnection - Connected to ...
04/01 10:19:05 DEBUG[on-spray-can-akka.actor.default-dispatcher-9] s.c.c.HttpHostConnectionSlot - Connection to ... established, dispatching 1 pending requests
04/01 10:19:05 DEBUG[on-spray-can-akka.actor.default-dispatcher-3] s.c.c.HttpClientConnection - now monitoring Actor[akka://on-spray-can/system/IO-TCP/selectors/$a/5]
04/01 10:19:05 DEBUG[on-spray-can-akka.actor.default-dispatcher-6] s.c.c.HttpHostConnectionSlot - Dispatching GET request to /api?params=values across connection Actor[akka://on-spray-can/user/IO-HTTP/group-0/4]
04/01 10:19:05 DEBUG[on-spray-can-akka.actor.default-dispatcher-6] s.c.c.HttpHostConnectionSlot - now monitoring Actor[akka://on-spray-can/user/IO-HTTP/group-0/4]
04/01 10:19:06 DEBUG[on-spray-can-akka.actor.default-dispatcher-3] s.c.c.HttpClientConnection - Dropping Close since the SSL connection is already closing
04/01 10:19:06 DEBUG[on-spray-can-akka.actor.default-dispatcher-3] s.c.c.HttpClientConnection - Connection was PeerClosed, awaiting TcpConnection termination...
04/01 10:19:06 DEBUG[on-spray-can-akka.actor.default-dispatcher-3] a.i.TcpOutgoingConnection - stopped
04/01 10:19:06 DEBUG[on-spray-can-akka.actor.default-dispatcher-3] s.c.c.HttpClientConnection - TcpConnection terminated, stopping
04/01 10:19:06 WARN [on-spray-can-akka.actor.default-dispatcher-3] s.c.c.HttpHostConnectionSlot - Premature connection close (the server doesn't appear to support request pipelining) in response to GET request to /myApi?params=values with 1 retries left, retrying...
04/01 10:19:06 DEBUG[on-spray-can-akka.actor.default-dispatcher-3] s.c.c.HttpClientConnection - stopped

我能够在所有这些版本中重现错误

spray 1.0.1; akka 2.0.5; scala 2.9.3
spray 1.2.1; akka 2.2.4; scala 2.10.1
spray 1.3.1; akka 2.3.0; scala 2.10.3
spray 1.3.2; akka 2.3.6; scala 2.11.4
spray 1.3.3; akka 2.3.9; scala 2.11.6


推荐答案

如您所说,


为确保这不是API的服务器问题,我使用Node.js复制了相同的
查询(Express和Request libs)并且每
次就可以使用一次。

To make sure this wasn’t the API’s server issue, I replicate the same query using Node.js (Express and Request libs) and it works every time. It makes me almost sure is a spray bug.

您在Scala中的代码使用HTTP流水线功能发送请求,您是否使用

your code in scala send requests with HTTP pipelining feature, do you send the requests with HTTP pipelining feature while you testing with nodejs?

错误消息:


服务器似乎不支持请求管道

the server doesn't appear to support request pipelining

您应确保:


  1. 请确保服务器支持流水线功能,并且启用了流水线功能。

  2. 如果客户端和服务器之间存在代理(包括反向代理),请确保代理支持流水线功能,并且启用了流水线功能。

如果您无法进行确保流水线功能可以得到正确的支持,您不应使用它。

If you can't make sure the pipelining feature can be supported properly, you should not use it.

以下资源可能会有所帮助:

following resource may helpful:


HTTP流水线需要客户端和服务器来支持它。需要
符合HTTP / 1.1的服务器才能支持管道传输。
并不意味着要求服务器通过管道传递响应,而是
要求它们在客户端选择通过管道传递
请求时不会失败。[7]

HTTP pipelining requires both the client and the server to support it. HTTP/1.1 conforming servers are required to support pipelining. This does not mean that servers are required to pipeline responses, but that they are required not to fail if a client chooses to pipeline requests.[7]

https://en.wikipedia。 org / wiki / HTTP_pipelining


现代浏览器默认不启用HTTP管道:

HTTP pipelining is not activated by default in modern browsers:

代理服务器仍然很普遍,这些导致Web开发人员无法轻易预测和诊断的奇怪且不稳定的
行为。
正确实施流水线很复杂:正在传输的资源
的大小,将使用的有效RTT以及
有效带宽,直接影响到改善
由管道提供。不知道这些,重要消息
可能会延迟到不重要的消息之后。重要的甚至
的概念在页面布局过程中也会演变!因此,HTTP流水线仅在大多数情况下会带来
的边际改进。流水线操作受到
HOL问题的影响。由于这些原因,流水线已被HTTP / 2使用的更好的
算法(多路复用)所取代。

Buggy proxies are still common and these lead to strange and erratic behaviors that Web developers cannot foresee and diagnose easily. Pipelining is complex to implement correctly: the size of the resource being transferred, the effective RTT that will be used, as well as the effective bandwidth, have a direct incidence on the improvement provided by the pipeline. Without knowing these, important messages may be delayed behind unimportant ones. The notion of important even evolves during page layout! HTTP pipelining therefore brings a marginal improvement in most cases only. Pipelining is subject to the HOL problem. For these reasons, pipelining has been superseded by a better algorithm, multiplexing, that is used by HTTP/2.

https://developer.mozilla.org/zh-CN/ docs / Web / HTTP / Connection_management_in_HTTP_1.x $ revision / 1330814

https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection_management_in_HTTP_1.x$revision/1330814

这篇关于由于SSL连接已经关闭,如何解决Droping Close的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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