gpt4 book ai didi

java - 如何在 openssl 上避免 jruby 的错误文件描述符?

转载 作者:太空宇宙 更新时间:2023-11-03 16:29:02 26 4
gpt4 key购买 nike

我在一个 java swing 应用程序中,它的 WebService 客户端是用 jruby 实现的。用例是用户单击按钮,相应的 Controller 打开一个新线程,该线程从本地数据库获取列表,并为列表的每个项目运行一个 jruby 脚本(通过 ScriptingContainer)。

jruby 的前 2 或 3 个调用总是成功,但随后抛出:

org.jruby.embed.EvalFailedException: (Errno::EBADF) Bad file descriptor
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1309)
at com.doctrans.AteaService.createMsgAndSend(AteaService.java:112)
at com.doctrans.AteaService.communicateTransportation(AteaService.java:85)
at com.doctrans.DocTransFacadeImpl.requestAteaCode(DocTransFacadeImpl.java:308)
at com.doctrans.DocTransFacadeImpl.requestAteaLoadStockCodes(DocTransFacadeImpl.java:132)
at com.doctrans.gui.controllers.RoutesCtrl$RequestTask.doInBackground(RoutesCtrl.java:501)
at com.doctrans.gui.controllers.RoutesCtrl$RequestTask.doInBackground(RoutesCtrl.java:1)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.jruby.exceptions.RaiseException: (Errno::EBADF) Bad file descriptor
at org.jruby.RubyIO.close(org/jruby/RubyIO.java:2052)
at org.jruby.ext.openssl.SSLSocket.sysclose(org/jruby/ext/openssl/SSLSocket.java:704)
at RUBY.close(jar:file:C:/DocTrans/data/DocTrans-2013.10.07.14.45.jar!/openssl/buffering.rb:447)
at RUBY.close(jar:file:C:/DocTrans/data/DocTrans-2013.10.07.14.45.jar!/net/protocol.rb:76)
at RUBY.transport_request(jar:file:C:/DocTrans/data/DocTrans-2013.10.07.14.45.jar!/net/http.rb:1338)
at RUBY.request(jar:file:C:/DocTrans/data/DocTrans-2013.10.07.14.45.jar!/net/http.rb:1301)
at RUBY.send_envio_documento_transporte(jar:file:C:/DocTrans/data/DocTrans-2013.10.07.14.45.jar!/pt/atea/client.rb:81)
at RUBY.(root)(send_request_for_app.rb:50)

这是为每个项目迭代的代码:

public String createMsgAndSend(RouteInfo routeInfo) throws IOException {
ScriptingContainer container = new ScriptingContainer(LocalContextScope.CONCURRENT);
String code = null;
try {
container.put("info", new Info());
container.put("route_info", routeInfo);
container.put("logger", LoggerFactory.getLogger("RubyClient"));
container.put("user", UserHolder.getCurrentUser()
.getUser());
container.put("pwd", UserHolder.getCurrentUser().getPwd());
RubyObject response = (RubyObject) container.runScriptlet(
PathType.CLASSPATH, "send_request_for_app.rb");
Ruby ruby = container.getRuntime();
boolean success = response.callMethod("fetch",
RubySymbol.newSymbol(ruby, "success")).isTrue();
LOGGER.info("Success?: " + success);
String error = (String) response.callMethod("fetch",
RubySymbol.newSymbol(ruby, "error")).asJavaString();
if (success && error.isEmpty()) {
code = (String) response.callMethod("fetch",
RubySymbol.newSymbol(ruby, "code")).asJavaString();
LOGGER.info("Response code: " + code);
} else {
throw new ServiceException(routeInfo, error);
}
} finally {
if (container != null) {
container.resetWriter();
container.resetErrorWriter();
container.clear();
container.terminate();
}
}
return code;
}

抛出异常的 jruby net/http 代码:

      http= Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.ssl_version = 'SSLv3'
http.open_timeout= 5000
http.cert = OpenSSL::X509::Certificate.new(pem)
http.key = OpenSSL::PKey::RSA.new(pem, pem_key)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Post.new(uri.request_uri)
http.finish if http.started?

我怀疑这可能与java线程有关,但不知道问题出在哪里。如何避免此 Bad file descriptor 异常?

最佳答案

我回答我自己的问题:这是 openssl 库中的错误。在 jruby 邮件列表中询问,他们建议升级。升级到 JRuby 1.7.5 解决了这个问题!

关于java - 如何在 openssl 上避免 jruby 的错误文件描述符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19242026/

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