我目前正在使用Play 2.2.1,并且在白天运行生产网络应用程序后,我开始在日志中收到以下错误。看起来我的连接已经不多了/我不能正确地关闭一些东西,但我似乎无法弄清楚它是什么。
2014-02-11 18:19:24,660 - [ERROR] - from play in play-akka.actor.default-dispatcher-31
Cannot invoke the action, eventually got an error: java.util.concurrent.ExecutionException: java.net.SocketException: Too many open files
2014-02-11 18:19:24,664 - [ERROR] - from application in play-akka.actor.default-dispatcher-31
! @6h8a5lf50 - Internal server error, for (POST) [/ws-tester/ajaxProcessInput?env=development&token=XXX&dataType=xml] ->
play.api.Application$$anon$1: Execution exception[[ExecutionException: java.net.SocketException: Too many open files]]
at play.api.Application$class.handleError(Application.scala:293) ~[com.typesafe.play.play_2.10-2.2.1.jar:2.2.1]
at play.api.DefaultApplication.handleError(Application.scala:399) [com.typesafe.play.play_2.10-2.2.1.jar:2.2.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [com.typesafe.play.play_2.10-2.2.1.jar:2.2.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [com.typesafe.play.play_2.10-2.2.1.jar:2.2.1]
at scala.Option.map(Option.scala:145) [org.scala-lang.scala-library-2.10.3.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2.applyOrElse(PlayDefaultUpstreamHandler.scala:261) [com.typesafe.play.play_2.10-2.2.1.jar:2.2.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2.applyOrElse(PlayDefaultUpstreamHandler.scala:257) [com.typesafe.play.play_2.10-2.2.1.jar:2.2.1]
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [org.scala-lang.scala-library-2.10.3.jar:na]
at play.api.libs.iteratee.Execution$$anon$1.execute(Execution.scala:43) [com.typesafe.play.play-iteratees_2.10-2.2.1.jar:2.2.1]
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Promise$class.complete(Promise.scala:55) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [org.scala-lang.scala-library-2.10.3.jar:na]
at play.api.libs.iteratee.Execution$$anon$2.execute(Execution.scala:70) [com.typesafe.play.play-iteratees_2.10-2.2.1.jar:2.2.1]
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Promise$class.complete(Promise.scala:55) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [org.scala-lang.scala-library-2.10.3.jar:na]
at play.api.libs.iteratee.Execution$$anon$2.execute(Execution.scala:70) [com.typesafe.play.play-iteratees_2.10-2.2.1.jar:2.2.1]
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.Promise$class.complete(Promise.scala:55) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23) [org.scala-lang.scala-library-2.10.3.jar:na]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42) [com.typesafe.akka.akka-actor_2.10-2.2.0.jar:2.2.0]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) [com.typesafe.akka.akka-actor_2.10-2.2.0.jar:2.2.0]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [org.scala-lang.scala-library-2.10.3.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [org.scala-lang.scala-library-2.10.3.jar:na]
Caused by: java.util.concurrent.ExecutionException: java.net.SocketException: Too many open files
at com.ning.http.client.providers.jdk.JDKFuture.get(JDKFuture.java:143) ~[com.ning.async-http-client-1.7.18.jar:na]
at com.ning.http.client.providers.jdk.JDKFuture.get(JDKFuture.java:118) ~[com.ning.async-http-client-1.7.18.jar:na]
at dispatch.HttpExecutor$$anonfun$apply$2$$anonfun$apply$3.apply(execution.scala:50) ~[net.databinder.dispatch.dispatch-core_2.10-0.11.0.jar:0.11.0]
at scala.util.Try$.apply(Try.scala:161) ~[org.scala-lang.scala-library-2.10.3.jar:na]
at dispatch.HttpExecutor$$anonfun$apply$2.apply(execution.scala:50) ~[net.databinder.dispatch.dispatch-core_2.10-0.11.0.jar:0.11.0]
at dispatch.HttpExecutor$$anonfun$apply$2.apply(execution.scala:50) ~[net.databinder.dispatch.dispatch-core_2.10-0.11.0.jar:0.11.0]
at dispatch.package$$anon$1.run(package.scala:18) ~[net.databinder.dispatch.dispatch-core_2.10-0.11.0.jar:0.11.0]
at scala.concurrent.impl.ExecutionContextImpl$$anon$3.exec(ExecutionContextImpl.scala:107) ~[org.scala-lang.scala-library-2.10.3.jar:na]
... 4 common frames omitted
java.net.SocketException: Too many open files
at java.net.Socket.createImpl(Socket.java:414) ~[na:1.6.0_18]
at java.net.Socket.connect(Socket.java:544) ~[na:1.6.0_18]
at sun.net.NetworkClient.doConnect(NetworkClient.java:169) ~[na:1.6.0_18]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:409) ~[na:1.6.0_18]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530) ~[na:1.6.0_18]
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:289) ~[na:1.6.0_18]
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:346) ~[na:1.6.0_18]
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) ~[na:1.6.0_18]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:914) ~[na:1.6.0_18]
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) ~[na:1.6.0_18]
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:979) ~[na:1.6.0_18]
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250) ~[na:1.6.0_18]
at com.ning.http.client.providers.jdk.JDKAsyncHttpProvider$AsyncHttpUrlConnection.configure(JDKAsyncHttpProvider.java:577) ~[com.ning.async-http-client-1.7.18.jar:na]
at com.ning.http.client.providers.jdk.JDKAsyncHttpProvider$AsyncHttpUrlConnection.call(JDKAsyncHttpProvider.java:238) ~[com.ning.async-http-client-1.7.18.jar:na]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.6.0_18]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.6.0_18]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) ~[na:1.6.0_18]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) ~[na:1.6.0_18]
at java.lang.Thread.run(Thread.java:636) ~[na:1.6.0_18]
主页面仍然显示,但应用程序在AJAX调用时失败。 Ajax函数非常简单:
def ajaxProcessInput(env : String, token : String , data : String, dataType : String) = Action {
dataType.toLowerCase() match {
case "csv" => {
val a = CSVObject(CSV.parse(data))
Ok(views.html.ajaxProvisioningResponse("(Not implemented yet) :: " + a.toString()))
}
case "xml" => {
ProvisioningServiceHandler.provision(environments.get(env),token = Base64Binary(token),data) match {
case Right(result) => { Ok(views.html.ajaxProvisioningResponse(result.resultData.getOrElse("No Result"))) }
case Left(error) => { InternalServerError(views.html.ajaxSOAPFault(error)) }
}
}
case _ => Ok("Invalid Data Type")
}
}
我用这块Coffee Script称呼它:
process = (entry,type) ->
jsRoutes.controllers.ServiceProvisioner.ajaxProcessInput($('#environment').find('option:selected').val(), $('#authToken').text(), $(entry).val(),type).ajax
success: (rr) ->
$('#provResponse').html rr
error: (rr) ->
$('#provResponse').html rr.responseText
$("#processCSV").click ->
process '#csvEntry','csv'
$("#processXML").click ->
process '#xmlEntry','xml'
如果重要,以下是我生成Javascript路径的方法:
def jsRoutes = Action { implicit request =>
Ok(
Routes.javascriptRouter("jsRoutes")
(routes.javascript.ServiceProvisioner.ajaxAuthToken,
routes.javascript.ServiceProvisioner.ajaxProcessInput)
).as("text/javascript")
}
以下是实际路线:
POST /ajaxProcessInput controllers.ServiceProvisioner.ajaxProcessInput(env : String, token : String , data : String, dataType : String)
GET /jsRoutes controllers.ServiceProvisioner.jsRoutes
我将它们包含在我的HTML视图中,如下所示:
<script type="text/javascript" src="@routes.ServiceProvisioner.jsRoutes"></script>
答案 0 :(得分:3)
根据堆栈跟踪,您正在使用调度HTTP客户端。我猜想每次你使用它时,你都在创建一个新的调度客户端实例,并且调度客户端正在启动线程池和连接池,然后你永远不会关闭它们,因此资源泄漏。
每次使用后关闭客户端,或使用单例客户端。您也可以使用Play的WS客户端而不是使用发送,Play管理其生命周期,以便您不必使用。