I’m making a call to an API, but most of the time I keep
getting an error: “Premature connection
close (the server doesn't appear to support request pipelining)”. Like 90%
of the time I get that error, meaning: in very rare occasions the query does
return the data it supposed to.
To make sure this wasn’t the API’s server issue, I replicate the exact same
query using Node.js (Express and Request libs) and it works every time. It
makes me almost sure is a spray issue.
Here's an example of the code:
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
Error detail:
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 /myApi?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
I was able to reproduce the error in
all of these versions:
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
# Options: OFF, ERROR, WARNING, INFO, DEBUG
loglevel = "DEBUG"
# Options: OFF, ERROR, WARNING, INFO, DEBUG
stdout-loglevel = "DEBUG"
actor {
debug {
receive = on
autoreceive = on
lifecycle = on
}
}
}
spray {
routing {
file-chunking-threshold-size = 30k
file-chunking-chunk-size = 15k
}
can{
server {
request-timeout = 30 s
idle-timeout = 40 s
timeout-timeout = 2 s
}
client {
response-chunk-aggregation-limit = 15m
}
}
}
- What is the java server software version? Apache Tomcat 6.0.20 - What is the JVM version that it runs on? OpenJDK Runtime Environment (IcedTea6 1.11.11.90) - Is there any custom configuration for handling SSL connections on this server? This Tomcat stack is frontend by an Amazon Elastic Load Balancer (ELB) that handles all inbound request including https(443) That is then passed to the Web Service layer handled by Apache/2.2.29 which then proxy request to the Tomcat Application Tier. - Is there any additional configuration made for handling client timeouts ? I'm not sure if we can had any additional configurations between the the ELB and Apache but this is where we would want to do any tuning if necessary. |
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/9b489e27-b975-4322-a51e-c3c22452be7f%40googlegroups.com.