Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6RC2
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: JRuby-extras
    • Labels:
      None
    • Environment:
      Linux
    • Number of attachments :
      0

      Description

      I tried to use the ruby-dbus gem to create desktop notifications from jruby. While it works in native ruby, jruby complains about the socket address.
      It would be great, if jruby could detect the unix socket type and use the RubyUNIXSocket appropriately instead raising an exception.

      Code triggering the behaviour (from bus.rb in the dbus gem)

      @socket = Socket.new(Socket::Constants::PF_UNIX,Socket::Constants::SOCK_STREAM, 0)
            @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
            if ! params['abstract'].nil?
              if HOST_END == LIL_END
                sockaddr = "\1\0\0#{params['abstract']}"
              else
                sockaddr = "\0\1\0#{params['abstract']}"
              end
            elsif ! params['path'].nil?
              sockaddr = Socket.pack_sockaddr_un(params['path'])
            end
            @socket.connect(sockaddr)
      

      The socket path is /tmp/dbus-kvq7FW2 and the error message raised is

      org/jruby/ext/socket/RubySocket.java:557:in `unpack_sockaddr_in': can't resolve socket address of wrong type (ArgumentError)
              from org/jruby/ext/socket/RubySocket.java:377:in `connect'
              from /home/tkruse/NetBeansProjects/Notify/rblib/dbus/bus.rb:269:in `connect_to_unix'
      

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        The problem we have in Socket is that it's the "everytool" for socket stuff in MRI, but in Java we have to choose the socket type at construction time. So there's no way we can have a single Socket class cover all types of sockets.

        I'm not sure we have any way to fix this at present. Why doesn't bus.rb just use UNIXSocket directly?

        Show
        Charles Oliver Nutter added a comment - The problem we have in Socket is that it's the "everytool" for socket stuff in MRI, but in Java we have to choose the socket type at construction time. So there's no way we can have a single Socket class cover all types of sockets. I'm not sure we have any way to fix this at present. Why doesn't bus.rb just use UNIXSocket directly?
        Hide
        Charles Oliver Nutter added a comment -

        Actually, I figured out a way to do this, since the socket type is being specified in the Socket constructor. I was able to get to the same error in ruby-dbus examples as Ruby 1.9.3, and I'm not sure how to go further. I think it's working; perhaps you can test JRuby master?

        commit bf7214b143a3d2b272dc3d01d66a6637406cdd2c
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Wed Apr 4 20:41:47 2012 -0500
        
            Add UNIX socket support to Socket class.
        
        Show
        Charles Oliver Nutter added a comment - Actually, I figured out a way to do this, since the socket type is being specified in the Socket constructor. I was able to get to the same error in ruby-dbus examples as Ruby 1.9.3, and I'm not sure how to go further. I think it's working; perhaps you can test JRuby master? commit bf7214b143a3d2b272dc3d01d66a6637406cdd2c Author: Charles Oliver Nutter <headius@headius.com> Date: Wed Apr 4 20:41:47 2012 -0500 Add UNIX socket support to Socket class.
        Hide
        Thomas Kruse added a comment -

        I tried to verify the fix, used jruby master from github. While the error message has changed, the socket connection still does not work.
        From what I can tell a valid unix socket connection is prepared, but the connect fails.

        (Since I am not sure where the problem originates I did not re-open the issue. Using ruby 1.8.7 to run the same script works.)

        SocketError: connect(2): name or service not known
                  connect at org/jruby/ext/socket/RubySocket.java:204
          connect_to_unix at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:269
                  connect at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:224
                     find at org/jruby/RubyEnumerable.java:548
                  connect at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:213
               initialize at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:705
                 instance at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:141
              synchronize at org/jruby/ext/thread/Mutex.java:149
                 instance at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:139
                   (root) at /home/tkruse/develop/NetBeansProjects/Notify/rb/notify.rb:4
                  require at org/jruby/RubyKernel.java:991
                   (root) at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:1
                  require at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:36
        Exception in thread "main" org.jruby.embed.EvalFailedException: (SocketError) connect(2): name or service not known
        	at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:132)
        	at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264)
        	at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1257)
        	at de.jugmuenster.notify.NotifyExample.main(NotifyExample.java:14)
        Caused by: org.jruby.exceptions.RaiseException: (SocketError) connect(2): name or service not known
        	at org.jruby.ext.socket.RubySocket.connect(org/jruby/ext/socket/RubySocket.java:204)
        	at RUBY.connect_to_unix(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:269)
        	at RUBY.connect(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:224)
        	at org.jruby.RubyEnumerable.find(org/jruby/RubyEnumerable.java:548)
        	at RUBY.connect(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:213)
        	at RUBY.initialize(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:705)
        	at RUBY.instance(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:141)
        	at org.jruby.ext.thread.Mutex.synchronize(org/jruby/ext/thread/Mutex.java:149)
        	at RUBY.instance(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:139)
        	at RUBY.(root)(/home/tkruse/develop/NetBeansProjects/Notify/rb/notify.rb:4)
        	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:991)
        	at RUBY.(root)(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:1)
        	at RUBY.require(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:36)
        Java Result: 1
        
        Show
        Thomas Kruse added a comment - I tried to verify the fix, used jruby master from github. While the error message has changed, the socket connection still does not work. From what I can tell a valid unix socket connection is prepared, but the connect fails. (Since I am not sure where the problem originates I did not re-open the issue. Using ruby 1.8.7 to run the same script works.) SocketError: connect(2): name or service not known connect at org/jruby/ext/socket/RubySocket.java:204 connect_to_unix at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:269 connect at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:224 find at org/jruby/RubyEnumerable.java:548 connect at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:213 initialize at /home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:705 instance at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:141 synchronize at org/jruby/ext/thread/Mutex.java:149 instance at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:139 (root) at /home/tkruse/develop/NetBeansProjects/Notify/rb/notify.rb:4 require at org/jruby/RubyKernel.java:991 (root) at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:1 require at jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:36 Exception in thread "main" org.jruby.embed.EvalFailedException: (SocketError) connect(2): name or service not known at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:132) at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264) at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1257) at de.jugmuenster.notify.NotifyExample.main(NotifyExample.java:14) Caused by: org.jruby.exceptions.RaiseException: (SocketError) connect(2): name or service not known at org.jruby.ext.socket.RubySocket.connect(org/jruby/ext/socket/RubySocket.java:204) at RUBY.connect_to_unix(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:269) at RUBY.connect(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:224) at org.jruby.RubyEnumerable.find(org/jruby/RubyEnumerable.java:548) at RUBY.connect(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:213) at RUBY.initialize(/home/tkruse/develop/NetBeansProjects/Notify/rblib/dbus/bus.rb:705) at RUBY.instance(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:141) at org.jruby.ext.thread.Mutex.synchronize(org/jruby/ext/thread/Mutex.java:149) at RUBY.instance(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/1.9/singleton.rb:139) at RUBY.(root)(/home/tkruse/develop/NetBeansProjects/Notify/rb/notify.rb:4) at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:991) at RUBY.(root)(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:1) at RUBY.require(jar:file:/home/tkruse/java/jruby/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:36) Java Result: 1

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Thomas Kruse
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: