scala – 如何修复Dropping Close,因为SSL连接已经关闭了喷涂中
我正在调用API,但大多数时候我一直收到错误:“自SSL连接已关闭后删除关闭”和“过早连接关闭(服务器似乎不支持请求流水线)”。 “就像90%的时间我得到了这个错误,这意味着:在非常罕见的情况下,查询会返回它应该的数据。
为了确保这不是API的服务器问题,我使用Node.js(Express和Request libs)复制相同的查询,并且它每次都有效。这让我几乎可以肯定是一个喷雾虫。 这是代码的示例: 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 解决方法
如你所说,
scala中的代码使用HTTP流水线功能发送请求,在使用nodejs进行测试时,是否使用HTTP流水线功能发送请求? 有关错误消息:
你应该确保: >请确保服务器支持流水线功能,并启用流水线功能。 如果无法确保可以正确支持流水线功能,则不应使用它。 以下资源可能有用:
https://en.wikipedia.org/wiki/HTTP_pipelining
https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection_management_in_HTTP_1.x $修订/ 1330814 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |