Understanding Simple Web App's Behavior with/ detch{} and Await.result

71 views
Skip to first unread message

Kevin Meredith

unread,
Jul 15, 2015, 3:31:05 PM7/15/15
to spray...@googlegroups.com
Given:

object Main extends App with SimpleRoutingApp {
  
  implicit val system = ActorSystem("my-system")

  val pipeline: HttpRequest => Future[String] = sendReceive ~> unmarshal[String]

  startServer(interface = "localhost", port = 8080) {
    path("block") {
      get { 
        detach() { 
          lazy val fut: Future[Int] = Future { Thread.sleep(20000); println("finished"); 100 }
          val res: Int = Await.result(fut, 45.seconds)
          complete(StatusCodes.OK)
        }
      }
    }
  }
}

Using POSTMAN, then I sent an HTTP GET to /block. Then, immediately after, I sent another HTTP Request to /block. 

The second request's output read:

Could not get any response

This seems to be like an error connecting to http://localhost:8080/block. The response status was 0.
Check out the W3C XMLHttpRequest Level 2 spec for more details about when this happens.


In addition, the first request also showed the above "Could not get any response" error:

Here's the SBT output:

$sbt run

[info] Set current project to gateway-automation (in build file:/Users/kmmere/Workspace/Work/simple_spray_app/)

[info] Compiling 1 Scala source to /Users/kmmere/Workspace/Work/simple_spray_app/target/scala-2.11/classes...

[info] Running net.Main 

[INFO] [07/15/2015 15:26:46.006] [my-system-akka.actor.default-dispatcher-3] [akka://my-system/user/IO-HTTP/listener-0] Bound to localhost/127.0.0.1:8080

[WARN] [07/15/2015 15:26:53.756] [my-system-akka.actor.default-dispatcher-5] [akka://my-system/user/IO-HTTP/listener-0/0] Configured registration timeout of 1 second expired, stopping

[WARN] [07/15/2015 15:26:55.337] [my-system-akka.actor.default-dispatcher-5] [akka://my-system/user/IO-HTTP/listener-0/1] Configured registration timeout of 1 second expired, stopping

finished

[INFO] [07/15/2015 15:27:05.666] [my-system-akka.actor.default-dispatcher-3] [akka://my-system/user/IO-HTTP/listener-0/0] Message [akka.io.Tcp$Register] from Actor[akka://my-system/deadLetters] to Actor[akka://my-system/user/IO-HTTP/listener-0/0#627369021] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

[INFO] [07/15/2015 15:27:05.666] [my-system-akka.actor.default-dispatcher-3] [akka://my-system/user/IO-HTTP/listener-0/1] Message [akka.io.Tcp$Register] from Actor[akka://my-system/deadLetters] to Actor[akka://my-system/user/IO-HTTP/listener-0/1#868710615] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.


What happened? 

Ravindra Bajpai

unread,
Sep 8, 2015, 8:20:28 AM9/8/15
to spray.io User List
Is there an answer for this. I am also facing the same issue. Found something got fixed here in the past...

Still not working for me.
Reply all
Reply to author
Forward
0 new messages