简体   繁体   English

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

[英]How to avoid jruby's Bad File Descriptor on openssl?

I'm in a java swing application which has its WebService client implemented in jruby. 我在一个Java Swing应用程序中,该应用程序的WebService客户端在jruby中实现。 The use case is User clicks on a button, the corresponding controller opens a new Thread and this thread takes a list from a local DB and for each item of the list runs a jruby script (through ScriptingContainer). 用例是用户单击按钮,相应的控制器打开一个新线程,该线程从本地数据库获取一个列表,并且该列表的每个项目都运行一个jruby脚本(通过ScriptingContainer)。

Always the first 2 or 3 calls that jruby does succeed, but then it throws: 总是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)

Here is the code which is iterated for each item: 这是为每个项目迭代的代码:

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;
}

The jruby net/http code which is throwing exception: 抛出异常的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?

I suspect that this may be related to java threads, but don't know where the problem is. 我怀疑这可能与Java线程有关,但不知道问题出在哪里。 How can I avoid this Bad file descriptor exception? 如何避免此错误文件描述符异常?

I answer my own question: It was a bug in the openssl lib. 我回答我自己的问题:这是openssl库中的错误。 Asked in the jruby mailing list and they recomended to upgrade. 在jruby邮件列表中被询问,他们建议升级。 Upgrading to JRuby 1.7.5 solved the problem! 升级到JRuby 1.7.5解决了该问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JRuby嵌入问题:放入失败,出现RaiseException:(Errno :: EBADF)错误的文件描述符 - JRuby Embedding prob: Puts appears to fails with RaiseException: (Errno::EBADF) Bad file descriptor JRuby-方法“ eval”的第二次调用给出(Errno :: EBADF)错误的文件描述符 - JRuby - second call of method “eval” gives (Errno::EBADF) Bad file descriptor 流集错误-错误的文件描述符 - Streamsets Error - Bad File Descriptor SocketException:sendto失败:EBADF(错误的文件描述符) - SocketException: sendto failed: EBADF (Bad file descriptor) RandomAccessFile.write: EBADF(坏文件描述符) - RandomAccessFile.write: EBADF (Bad file descriptor) 使用file.length时错误的文件描述符异常 - Bad file descriptor exception when using file.length Windows 7 for Java项目下的gettext返回“错误文件描述符” - gettext under windows 7 for java project returns 'Bad file descriptor' 使用javax.xml的Java中的错误文件描述符IOException - Bad File Descriptor IOException in Java using javax.xml 从InputStream读取时SocketException错误的文件描述符 - SocketException bad file descriptor when reading from InputStream 在执行 Perl 期间出现错误“错误文件描述符” - Giving error 'Error Bad file descriptor' during execution of Perl
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM