gpt4 book ai didi

java - Play 2.2 框架中打开的文件(套接字)过多

转载 作者:行者123 更新时间:2023-12-01 23:12:20 29 4
gpt4 key购买 nike

我目前使用的是 Play 2.2.1,在白天运行生产 Web 应用程序后,我的日志中开始出现以下错误。似乎我的连接已用完/我一定没有正确关闭某些东西,但我似乎无法弄清楚它是什么。

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")
}
}

我用这段 CoffeeScript 来调用它:

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 View 中,如下所示:

<script type="text/javascript" src="@routes.ServiceProvisioner.jsRoutes"></script>

最佳答案

根据堆栈跟踪,您正在使用调度 HTTP 客户端。我猜想每次你使用它时,你都会创建一个调度客户端的新实例,并且调度客户端正在启动线程池和连接池,然后你永远不会关闭它们,因此资源泄漏。

每次使用后关闭客户端,或使用单例客户端。您还可以使用 Play 的 WS 客户端而不是使用调度,Play 会管理其生命周期,因此您不必这样做。

关于java - Play 2.2 框架中打开的文件(套接字)过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21693970/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com