Re: [spray-user] PeerClosed error running spray-client

420 views
Skip to first unread message

Mathias

unread,
Aug 23, 2012, 5:19:25 PM8/23/12
to spray...@googlegroups.com
Stephen,

since you are not the first to report this type of error with the 1.0-M2 spray-client I'm inclined to suspect a problem somewhere on the spray-side.
In order to be able to dig this thing up I need to reproduce it.
Is one of your "problematic URLs" publicly available?

Cheers,
Mathias

---
mat...@spray.cc
http://www.spray.cc

On 23.08.2012, at 16:43, stevem wrote:

> Hi
>
> I've started using spray-client to perform web page fetches. The pared down code for performing the fetch is basically this:
>
> val conduit = new HttpConduit(httpClient, "....")
> val responseFuture = conduit.sendReceive(HttpRequest(method = HttpMethods.GET, uri = "...."))
>
> The spray-client config is:
>
> spray.client {
> max-connections = 10
> max-retries = 5
> }
>
> spray.can {
> client {
> request-timeout = 3000 s
> }
> }
>
> I'm running spray-template with additional dependencies on spray-client and spray version 1.0-M2.
>
> The issue is that for some URLs, spray returns the following error:
> ....
> c.s.i.IoWorker - Reading from connection
> c.s.i.IoWorker - Read 1458 bytes
> c.s.i.IoWorker - Reading from connection
> c.s.i.IoWorker - Read 418 bytes
> c.s.i.IoWorker - Reading from connection
> c.s.i.IoWorker - Closing connection due to PeerClosed
> c.s.c.c.HttpClient - Stopping connection actor, connection was closed due to PeerClosed
> c.s.c.HttpConduit$MainActor - Received 'java.lang.RuntimeException: Connection closed, reason: PeerClosed' in response to GET request to ....
>
> I am able to fetch pages from other websites with no changes to the above code or config. Similarly, i've been able to fetch the problematic URLs using JSoup and Dispatch.
>
> If this is familiar to anyone any help would be much appreciated.
>
> Regards
>
> --
>
>

stevem

unread,
Aug 30, 2012, 11:36:46 AM8/30/12
to spray...@googlegroups.com

Mathias

unread,
Aug 31, 2012, 11:44:13 AM8/31/12
to spray...@googlegroups.com
Thanks, Steve, we'll investigate this...

Cheers,
Mathias

---
mat...@spray.cc
http://www.spray.cc

> --
>
>

Mathias

unread,
Sep 3, 2012, 5:54:04 AM9/3/12
to spray...@googlegroups.com
Stephen,

I have tried fetching this URL with an adaption of the simple-spray-client example.
It works flawlessly.

What OS are you on?
Could you try to GET one of your problematic URLs with this code [here][1] as well?

Cheers,
Mathias

[1]: https://github.com/spray/spray/blob/release-1.0-M2/examples/spray-client/simple-spray-client/src/main/scala/cc/spray/examples/client/Main.scala#L41

---
mat...@spray.cc
http://www.spray.cc

On 30.08.2012, at 17:36, stevem wrote:

> --
>
>

Stephen Matthew

unread,
Sep 4, 2012, 9:05:39 AM9/4/12
to spray...@googlegroups.com
Hi Matthias

Thanks for running against my URL. The example code you suggested is
the one i'm already using.

Could i ask what version of spray did you use?

Regards
Steve
> --
>
>

Mathias

unread,
Sep 4, 2012, 9:07:12 AM9/4/12
to spray...@googlegroups.com
Steve,

I tried it with 1.0-M2, and it worked without any problem.
Are you on Windows?

Cheers,
Mathias

---
mat...@spray.cc
http://www.spray.cc

> --
>
>

Stephen Matthew

unread,
Sep 4, 2012, 9:10:10 AM9/4/12
to spray...@googlegroups.com
I'm on OSX.

I'll run example code from a different machine/IP as this is one of
the remaining variables.

Regards
Steve
> --
>
>

Mathias

unread,
Sep 4, 2012, 9:11:34 AM9/4/12
to spray...@googlegroups.com
Ok, OSX myself as well.
What JDK?

---
mat...@spray.cc
http://www.spray.cc
> --
>
>

Stephen Matthew

unread,
Sep 4, 2012, 9:16:53 AM9/4/12
to spray...@googlegroups.com
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode).

Also:
akka 2.0
spray1.0-M2
scala 2.9.1
> --
>
>

Mathias

unread,
Sep 4, 2012, 9:23:42 AM9/4/12
to spray...@googlegroups.com
Ok, so you are on Java 1.6.0_33 as I am.
Let's take this offline, I'll shoot you an email.

Cheers,
Mathias

---
mat...@spray.cc
http://www.spray.cc

> --
>
>

Mathias

unread,
Oct 15, 2012, 3:47:09 AM10/15/12
to spray...@googlegroups.com
> I'm on
> OSX 10.7.4,
> using JDK "1.6.0_35" Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811) Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)
> Scala 2.9.2,
> Spray 1.0-M2

If you are only using spray-client then upgrading to 1.0-M3 shouldn't be too much of a problem.
Could you try again with the latest release?

Cheers,
Mathias

---
mat...@spray.io
http://www.spray.io

On 15.10.2012, at 09:44, Anirvan Chakraborty wrote:

> Hi Guys,
>
> I'm experiencing exactly the same issue of "Closing connection due to PeerClosed" as reported by stevem.
>
> Here is my stack trace:
>
> [DEBUG] [10/15/2012 08:17:26.906] [SYNC-akka.actor.default-dispatcher-2] [akka://SYNC/user/$c] started (cc.spray.client.HttpConduit$MainActor@254a6c0d)
>
> [DEBUG] [10/15/2012 08:17:26.907] [SYNC-akka.actor.default-dispatcher-2] [akka://SYNC/user/$c] Opening connection 1 to www.google.co.uk:80
>
> [DEBUG] [10/15/2012 08:17:26.910] [SYNC-akka.actor.default-dispatcher-2] [akka://SYNC/user/$c] stopped
>
> [DEBUG] [10/15/2012 08:17:31.697] [spray-io-worker-0] [IoWorker] Executing command Send(cc.spray.io.ConnectionActors$$anon$1@7a8f9805,List(java.nio.HeapByteBuffer[pos=0 lim=232 cap=1024]),true)
>
> [DEBUG] [10/15/2012 08:17:31.697] [spray-io-worker-0] [IoWorker] Writing to connection
>
> [DEBUG] [10/15/2012 08:17:31.698] [spray-io-worker-0] [IoWorker] Writing to connection
>
> [DEBUG] [10/15/2012 08:17:31.698] [spray-io-worker-0] [IoWorker] Wrote 0 bytes
>
> [DEBUG] [10/15/2012 08:17:31.856] [spray-io-worker-0] [IoWorker] Reading from connection
>
> [DEBUG] [10/15/2012 08:17:31.856] [spray-io-worker-0] [IoWorker] Read 405 bytes
>
> [DEBUG] [10/15/2012 08:17:31.859] [SYNC-akka.actor.default-dispatcher-3] [akka://SYNC/user/$b] Received HttpRequest(GET,/favicon.ico,List(Cookie: m="3234:t|6493:t|6967:t|34e2:|47ba:t|c01:t"; splashShown1.6="1", Accept-Charset: ISO-8859-1, UTF-8, *, Accept-Language: en-US, en, Accept-Encoding: gzip, deflate, sdch, user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4, Accept: */*, Connection: keep-alive, Host: localhost:8899),None,HTTP/1.1) with one attached service, dispatching...
>
> [DEBUG] [10/15/2012 08:17:31.859] [SYNC-akka.actor.default-dispatcher-2] [akka://SYNC/user/root-service] Received HttpRequest(GET,/favicon.ico,List(Cookie: m="3234:t|6493:t|6967:t|34e2:|47ba:t|c01:t"; splashShown1.6="1", Accept-Charset: ISO-8859-1, UTF-8, *, Accept-Language: en-US, en, Accept-Encoding: gzip, deflate, sdch, user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4, Accept: */*, Connection: keep-alive, Host: localhost:8899),None,HTTP/1.1) with one attached service, dispatching...
>
> [DEBUG] [10/15/2012 08:17:31.863] [spray-io-worker-0] [IoWorker] Executing command Send(cc.spray.io.ConnectionActors$$anon$1@7a8f9805,List(java.nio.HeapByteBuffer[pos=0 lim=174 cap=1024]),true)
>
> [DEBUG] [10/15/2012 08:17:31.864] [spray-io-worker-0] [IoWorker] Writing to connection
>
> [DEBUG] [10/15/2012 08:17:31.864] [spray-io-worker-0] [IoWorker] Writing to connection
>
> [DEBUG] [10/15/2012 08:17:31.864] [spray-io-worker-0] [IoWorker] Wrote 0 bytes
>
> [DEBUG] [10/15/2012 08:17:41.880] [SYNC-akka.actor.default-dispatcher-3] [akka://SYNC/user/sync-server] Closing connection due to idle timeout...
>
> [DEBUG] [10/15/2012 08:17:41.881] [spray-io-worker-0] [IoWorker] Executing command Close(cc.spray.io.ConnectionActors$$anon$1@7a8f9805,IdleTimeout)
>
> [DEBUG] [10/15/2012 08:17:41.881] [spray-io-worker-0] [IoWorker] Closing connection due to IdleTimeout
>
> [DEBUG] [10/15/2012 08:17:41.881] [SYNC-akka.actor.default-dispatcher-3] [akka://SYNC/user/sync-server] Stopping connection actor, connection was closed due to IdleTimeout
>
> [DEBUG] [10/15/2012 08:17:41.882] [SYNC-akka.actor.default-dispatcher-3] [akka://SYNC/user/sync-server/$a] stopped
>
> [DEBUG] [10/15/2012 08:17:42.89] [spray-io-worker-0] [IoWorker] Reading from connection
>
> [DEBUG] [10/15/2012 08:17:42.90] [spray-io-worker-0] [IoWorker] Closing connection due to PeerClosed
>
> [DEBUG] [10/15/2012 08:17:42.90] [SYNC-akka.actor.default-dispatcher-3] [akka://SYNC/user/sync-server] Stopping connection actor, connection was closed due to PeerClosed
>
> [DEBUG] [10/15/2012 08:17:42.90] [SYNC-akka.actor.default-dispatcher-3] [akka://SYNC/user/sync-server/$b] stopped
>
> I'm on
> OSX 10.7.4,
> using JDK "1.6.0_35" Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811) Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)
> Scala 2.9.2,
> Spray 1.0-M2
>
> What are we missing here?
>
> Any help would be much appreciated.
>
> Thanks,
> Ani.
> --
>
>

Anirvan Chakraborty

unread,
Oct 15, 2012, 3:52:55 AM10/15/12
to spray...@googlegroups.com
Hi Mathias,

Thanks for the *super* quick response.

We are actually using spray, spray-can, spray-server as well! So upgrading to 1.0-M3 would be an issue, as quite a lot has changed on the latest release.

Is there anything else we could do?

Thanks,
Ani.

Mathias

unread,
Oct 15, 2012, 4:00:43 AM10/15/12
to spray...@googlegroups.com
Ani,

the problem is that I still cannot reproduce the issue from my end.
If you managed to distill a minimal failing test we could apply a fix and release a patch for 1.0-M2.

Cheers,
Mathias

---
mat...@spray.io
http://www.spray.io

> --
>
>

Tomáš Heřman

unread,
Mar 27, 2013, 3:19:48 PM3/27/13
to spray...@googlegroups.com
Hello guys,
sorry to resurrect this thread but any news on this issue? I keep getting it with this code:
   https://github.com/tomasherman/scalacrawler  (sorry about how fugly it is ;)

The errors are:

[info] Running scalacrawler.Main
(beta.tech-specs.com,/)[INFO] [03/27/2013 20:18:46.472] [default-1] [akka://default/user/io-bridge] akka
://default/user/io-bridge started                                                                     
[INFO] [03/27/2013 20:18:46.836] [default-akka.actor.default-dispatcher-4] [akka://default/user/$a] Star
ting akka://default/user/$a                                                                           
[WARN] [03/27/2013 20:18:47.154] [default-akka.actor.default-dispatcher-4] [akka://default/user/$a] Rece
ived illegal response: The server does not support the HTTP protocol version used in the request.     
[WARN] [03/27/2013 20:18:47.416] [default-akka.actor.default-dispatcher-5] [akka://default/user/$a] Rece
ived illegal response: The server does not support the HTTP protocol version used in the request.     
[WARN] [03/27/2013 20:18:47.675] [default-akka.actor.default-dispatcher-4] [akka://default/user/$a] Rece
ived illegal response: The server does not support the HTTP protocol version used in the request.     
[WARN] [03/27/2013 20:18:47.939] [default-akka.actor.default-dispatcher-5] [akka://default/user/$a] Rece
ived illegal response: The server does not support the HTTP protocol version used in the request.     
[WARN] [03/27/2013 20:18:48.196] [default-akka.actor.default-dispatcher-8] [akka://default/user/$a] Rece
ived illegal response: The server does not support the HTTP protocol version used in the request.     
[error] (run-main) java.lang.RuntimeException: Connection closed, reason: PeerClosed

java.lang.RuntimeException: Connection closed, reason: PeerClosed
        at spray.client.HttpConduit$$anonfun$receive$1.apply(HttpConduit.scala:57)
        at spray.client.HttpConduit$$anonfun$receive$1.apply(HttpConduit.scala:46)
        at akka.actor.Actor$class.apply(Actor.scala:318)
        at spray.client.HttpConduit.apply(HttpConduit.scala:29)
        at akka.actor.ActorCell.invoke(ActorCell.scala:626)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)
        at akka.dispatch.Mailbox.run(Mailbox.scala:179)
        at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala
:516)                                                                                                 
        at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
        at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
        at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)
        at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
[WARN] [03/27/2013 20:18:48.457] [default-akka.actor.default-dispatcher-5] [akka://default/user/$a] Rece
ived illegal response: The server does not support the HTTP protocol version used in the request.     
[INFO] [03/27/2013 20:18:48.477] [default-akka.actor.default-dispatcher-3] [akka://default/user/$a] Stop
ped akka://default/user/$a                                                                            
[INFO] [03/27/2013 20:18:48.480] [default-1] [akka://default/user/io-bridge] akka://default/user/io-brid
ge stopped                                                                                            
java.lang.RuntimeException: Nonzero exit code: 1
        at scala.sys.package$.error(package.scala:27)
[error] {file:/home/tomasherman/workspace/scalacrawler/}default-ef5d54/compile:run: Nonzero exit code: 1
[error] Total time: 12 s, completed Mar 27, 2013 8:18:48 PM


Thanks, Tomas

Mathias

unread,
Mar 28, 2013, 5:21:25 AM3/28/13
to spray...@googlegroups.com
Tomáš,

this issue should not appear any more with the new client implementation in the master branch (and the latest nightlies).
If you have trouble upgrading we'll try to help where we can.

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "spray-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Tomáš Heřman

unread,
Mar 28, 2013, 7:56:21 AM3/28/13
to spray...@googlegroups.com
Great, thanks!

Denis

unread,
Jun 5, 2013, 2:42:23 PM6/5/13
to spray...@googlegroups.com
This is happening to my on M7.

java.lang.RuntimeException: Connection closed, reason: RequestTimeout
at spray.client.HttpConduit$$anonfun$receive$1.applyOrElse(HttpConduit.scala:57) ~[spray-client-1.1-M7.jar:1.1-M7]
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425) ~[akka-actor_2.10.0-RC5-2.1.0-RC6.jar:na]
at akka.actor.ActorCell.invoke(ActorCell.scala:386) ~[akka-actor_2.10.0-RC5-2.1.0-RC6.jar:na]

Thanks.

Mathias

unread,
Jun 5, 2013, 4:34:45 PM6/5/13
to spray...@googlegroups.com
Denis,

this error is triggered when the server you send the request to doesn't respond within the configured request-timeout period.
You can configure this timeout with this config setting:
https://github.com/spray/spray/blob/v1.1-M7/spray-can/src/main/resources/reference.conf#L116

Cheers,
Mathias

---
mat...@spray.io
http://spray.io

Denis

unread,
Jun 5, 2013, 5:09:29 PM6/5/13
to spray...@googlegroups.com
Hi Mathias - thanks for your reply, but i can't seem to set request-timeout setting since conduit settings only define the following properties. I am setting the settings of a particular conduit instance via: HttpClientConfig.

class ConduitSettings(config: Config) {
  protected val c: Config = ConfigUtils.prepareSubConfig(config, "spray.client")

  val MaxConnections       = c getInt "max-connections"
  val MaxRetries           = c getInt "max-retries"
  val WarnOnIllegalHeaders = c getBoolean "warn-on-illegal-headers"

  require(MaxConnections >  0, "max-connections must be > 0")
  require(MaxRetries     >= 0, "max-retries must be >= 0")

Mathias

unread,
Jun 5, 2013, 5:13:10 PM6/5/13
to spray...@googlegroups.com
Denis,

in M7 the request-timeout is a setting of the HttpClient you use your HttpConduit with:
https://github.com/spray/spray/blob/v1.1-M7/spray-can/src/main/scala/spray/can/client/HttpClient.scala#L36

Cheers,
Mathias

---
mat...@spray.io
http://spray.io

On 05.06.2013, at 23:09, Denis <dsa...@jetsetter.com> wrote:

> Hi Mathias - thanks for your reply, but i can't seem to set request-timeout
> setting since conduit settings only define the following properties. I am
> setting the settings of a particular conduit instance via: HttpClientConfig.
>
> class ConduitSettings(config: Config) {
> protected val c: Config = ConfigUtils.prepareSubConfig(config,
> "spray.client")
>
> * val MaxConnections = c getInt "max-connections"*
> * val MaxRetries = c getInt "max-retries"*
> * val WarnOnIllegalHeaders = c getBoolean "warn-on-illegal-headers"*
>
> require(MaxConnections > 0, "max-connections must be > 0")
> require(MaxRetries >= 0, "max-retries must be >= 0")
> }
>
> On Wednesday, June 5, 2013 4:34:45 PM UTC-4, Mathias wrote:
>>
>> Denis,
>>
>> this error is triggered when the server you send the request to doesn't
>> respond within the configured request-timeout period.
>> You can configure this timeout with this config setting:
>>
>> https://github.com/spray/spray/blob/v1.1-M7/spray-can/src/main/resources/reference.conf#L116
>>
>> Cheers,
>> Mathias
>>
>> ---
>> mat...@spray.io <javascript:>
>> http://spray.io
>>
>> On 05.06.2013, at 20:42, Denis <dsa...@jetsetter.com <javascript:>>
>> an email to spray-user+...@googlegroups.com <javascript:>.

Denis

unread,
Jun 5, 2013, 5:31:32 PM6/5/13
to spray...@googlegroups.com
Thanks Mathias. Yup, I just noticed it and was going to comment that I can provide this setting in ClientSettings :) Thanks again for you prompt responses. 

Cheers.
Reply all
Reply to author
Forward
0 new messages