title: How to fix the Dropping Close since the SSL connection is already closing error in spray
body: <p>I’m making a call to an API, but most of the time I keep getting an error: “<strong>Dropping Close since the SSL connection is already closing</strong>” and “<strong>Premature connection close (the server doesn't appear to support request pipelining)</strong>.” Like 90% of the time I get that error, meaning: on very rare occasions the query does return the data it supposed to.</p>
  
  <p><em>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</em>.</p>
  
  <p><strong>Here's an example of the code</strong>:</p>
  
  <pre><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 =&gt; {
        val credentials: BasicHttpCredentials = BasicHttpCredentials(myClass.user, myClass.pass)
        val url: String = "https://myApi?params=values"
        val request: HttpRequest = Get(url) ~&gt; addCredentials(credentials)
        val pipeline = sendReceive
        val response: Future[HttpResponse] = pipeline(request)
        val finalRes: Future[String] = response.map{ r =&gt;
          println(r)
          r.entity.asString
        }
        finalRes pipeTo sender
      }
    } // end receive
  } //end Actor
  </code></pre>
  
  <p><strong>Error Detail</strong>:</p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>And I was able to reproduce the error in all of these versions</strong>:</p>
  
  <pre><code>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
  </code></pre>