{"action":"created","issue":{"url":"https://api.github.com/repos/http4s/http4s/issues/231","labels_url":"https://api.github.com/repos/http4s/http4s/issues/231/labels{/name}","comments_url":"https://api.github.com/repos/http4s/http4s/issues/231/comments","events_url":"https://api.github.com/repos/http4s/http4s/issues/231/events","html_url":"https://github.com/http4s/http4s/issues/231","id":62469806,"number":231,"title":"Shutdown server on request","user":{"login":"sameersingh","id":585359,"avatar_url":"https://avatars.githubusercontent.com/u/585359?v=3","gravatar_id":"","url":"https://api.github.com/users/sameersingh","html_url":"https://github.com/sameersingh","followers_url":"https://api.github.com/users/sameersingh/followers","following_url":"https://api.github.com/users/sameersingh/following{/other_user}","gists_url":"https://api.github.com/users/sameersingh/gists{/gist_id}","starred_url":"https://api.github.com/users/sameersingh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sameersingh/subscriptions","organizations_url":"https://api.github.com/users/sameersingh/orgs","repos_url":"https://api.github.com/users/sameersingh/repos","events_url":"https://api.github.com/users/sameersingh/events{/privacy}","received_events_url":"https://api.github.com/users/sameersingh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/http4s/http4s/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":{"login":"bryce-anderson","id":2948506,"avatar_url":"https://avatars.githubusercontent.com/u/2948506?v=3","gravatar_id":"","url":"https://api.github.com/users/bryce-anderson","html_url":"https://github.com/bryce-anderson","followers_url":"https://api.github.com/users/bryce-anderson/followers","following_url":"https://api.github.com/users/bryce-anderson/following{/other_user}","gists_url":"https://api.github.com/users/bryce-anderson/gists{/gist_id}","starred_url":"https://api.github.com/users/bryce-anderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bryce-anderson/subscriptions","organizations_url":"https://api.github.com/users/bryce-anderson/orgs","repos_url":"https://api.github.com/users/bryce-anderson/repos","events_url":"https://api.github.com/users/bryce-anderson/events{/privacy}","received_events_url":"https://api.github.com/users/bryce-anderson/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2015-03-17T17:53:05Z","updated_at":"2015-05-28T10:40:02Z","closed_at":"2015-03-19T12:09:53Z","body":"I need a server that I can terminate from client side using a request, and am struggling to get it working.\r\n\r\nHere's what my attempt looks like:\r\n````scala\r\nobject Server extends App {\r\n  var task: Server = _\r\n  val blaze = BlazeBuilder.bindHttp(8080)\r\n\r\n  val service = HttpService {\r\n    case req@GET -> Root / \"hello\" =>\r\n      Ok(\"Hello, better world.\")\r\n    case req@GET -> Root / \"shutdown\" => {\r\n      Task({ Thread.sleep(2000); task.shutdownNow(); }).runAsync(_ match { case -\\/(e) => e.printStackTrace(); })\r\n      Ok(\"Bye!\")\r\n    }\r\n  }\r\n\r\n  task = blaze.mountService(service).run\r\n  task.awaitShutdown()\r\n  println(\"Server shut down.\") // I need to continue from here\r\n}\r\n````\r\n\r\nWhen I send the `localhost:8080/shutdown` `POST` request, I get back a `Bye!` response, but the server doesn't terminate and the process never prints the `Server shut down.` string. Instead, I get the following (after 2 seconds):\r\n\r\n````\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-0\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-1\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-2\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-3\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-4\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-5\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-6\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-7\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-8\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-9\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-10\r\n[error] [pool-1-thread-2] INFO org.http4s.blaze.channel.nio1.SelectorLoop - Shutting down SelectorLoop FixedPoolLoop-11\r\n[error] java.io.IOException: No such file or directory\r\n[error] \tat sun.nio.ch.NativeThread.signal(Native Method)\r\n[error] \tat sun.nio.ch.ServerSocketChannelImpl.implCloseSelectableChannel(ServerSocketChannelImpl.java:283)\r\n[error] \tat java.nio.channels.spi.AbstractSelectableChannel.implCloseChannel(AbstractSelectableChannel.java:234)\r\n[error] \tat java.nio.channels.spi.AbstractInterruptibleChannel.close(AbstractInterruptibleChannel.java:115)\r\n[error] \tat org.http4s.blaze.channel.nio1.NIO1ServerChannelFactory$NIO1ServerChannel.close(NIO1ServerChannelFactory.scala:39)\r\n[error] \tat org.http4s.server.blaze.BlazeBuilder$$anonfun$start$1$$anon$1$$anonfun$shutdown$1.apply(BlazeServer.scala:117)\r\n[error] \tat org.http4s.server.blaze.BlazeBuilder$$anonfun$start$1$$anon$1$$anonfun$shutdown$1.apply(BlazeServer.scala:116)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$delay$1.apply(Task.scala:266)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$delay$1.apply(Task.scala:266)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$suspend$1$$anonfun$4.apply(Task.scala:274)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$suspend$1$$anonfun$4.apply(Task.scala:274)\r\n[error] \tat scalaz.concurrent.Task$.Try(Task.scala:379)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$suspend$1.apply(Task.scala:274)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$suspend$1.apply(Task.scala:274)\r\n[error] \tat scalaz.concurrent.Future.step(Future.scala:110)\r\n[error] \tat scalaz.concurrent.Future.listen(Future.scala:76)\r\n[error] \tat scalaz.concurrent.Future.runAsync(Future.scala:143)\r\n[error] \tat scalaz.concurrent.Future.run(Future.scala:160)\r\n[error] \tat scalaz.concurrent.Task.run(Task.scala:97)\r\n[error] \tat org.http4s.server.Server$class.shutdownNow(Server.scala:12)\r\n[error] \tat org.http4s.server.blaze.BlazeBuilder$$anonfun$start$1$$anon$1.shutdownNow(BlazeServer.scala:115)\r\n[error] \tat collective_ie.interactive.Server$$anonfun$1$$anonfun$2.apply(Http4sUI.scala:44)\r\n[error] \tat collective_ie.interactive.Server$$anonfun$1$$anonfun$2.apply(Http4sUI.scala:44)\r\n[error] \tat scalaz.concurrent.Task$.Try(Task.scala:379)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$apply$10.apply(Task.scala:281)\r\n[error] \tat scalaz.concurrent.Task$$anonfun$apply$10.apply(Task.scala:281)\r\n[error] \tat scalaz.concurrent.Future$$anonfun$apply$15$$anon$3.call(Future.scala:367)\r\n[error] \tat scalaz.concurrent.Future$$anonfun$apply$15$$anon$3.call(Future.scala:367)\r\n[error] \tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\r\n[error] \tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\r\n[error] \tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\r\n[error] \tat java.lang.Thread.run(Thread.java:745)\r\n````\r\n\r\nAny ideas how I can achieve this?"},"comment":{"url":"https://api.github.com/repos/http4s/http4s/issues/comments/106268318","html_url":"https://github.com/http4s/http4s/issues/231#issuecomment-106268318","issue_url":"https://api.github.com/repos/http4s/http4s/issues/231","id":106268318,"user":{"login":"Verneri","id":975436,"avatar_url":"https://avatars.githubusercontent.com/u/975436?v=3","gravatar_id":"","url":"https://api.github.com/users/Verneri","html_url":"https://github.com/Verneri","followers_url":"https://api.github.com/users/Verneri/followers","following_url":"https://api.github.com/users/Verneri/following{/other_user}","gists_url":"https://api.github.com/users/Verneri/gists{/gist_id}","starred_url":"https://api.github.com/users/Verneri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Verneri/subscriptions","organizations_url":"https://api.github.com/users/Verneri/orgs","repos_url":"https://api.github.com/users/Verneri/repos","events_url":"https://api.github.com/users/Verneri/events{/privacy}","received_events_url":"https://api.github.com/users/Verneri/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T10:40:02Z","updated_at":"2015-05-28T10:40:02Z","body":"It seems i have this problem with java 8 but not with java 7. (and i'm using http4s v0.7.0)"}}