Gem hangs => TCPSocket.write hangs

Discussion in 'Ruby' started by Tim Shadel, Jul 23, 2005.

  1. Tim Shadel

    Tim Shadel Guest

    Well, I tried deleting the cache and that didn't work. So I dug in
    and tried to find the call that was hanging. I eventually traced it
    down to the TCPSocket.write call inside the HTTP module. Here's a
    snippet from irb that shows the problem:

    C:\>irb
    irb(main):001:0> require 'socket'
    =3D> true
    irb(main):002:0> sock =3D TCPSocket.new("gems.rubyforge.org", 80)
    =3D> #<TCPSocket:0x2d3c960>
    irb(main):003:0> sock.write "GET /yaml.Z HTTP/1.1\r\nHost:
    gems.rubyforge.org\r\n\r\n"

    (Hangs)

    I also tried to write a small script to show the problem.

    -------
    require 'socket'

    hostname =3D ARGV[0]
    puts "Making socket to #{hostname}"
    sock =3D TCPSocket.new(hostname, 80)
    mesg =3D "GET /yaml.Z HTTP/1.1\r\nHost: #{hostname}\r\n\r\n"
    puts "writing to socket #{hostname}: " + mesg
    sock.write mesg
    puts "Wow, no hang!"
    -----

    Here's the output:

    ------
    C:\>ruby test.rb google.com
    Making socket to google.com
    writing to socket google.com: GET /yaml.Z HTTP/1.1
    Host: google.com

    ------

    But wget works, so my internet connection is fine, DNS resolves the
    names, and I don't have any problems communicating with either
    gems.rubyforge.org or google.com.

    Even trying a connection to localhost:8080 (Tomcat) failed.

    So any idea how I can fix this problem? It just seems like Ruby can't
    write to any sockets at all, or am I misinterpreting the symptoms.

    I'd truly love to start working with Ruby, and I'm very interested in
    Rails, but I can't see how I can really dive in unless I can get
    sockets to just work.

    Thanks in advance for your help,

    Tim


    On 7/13/05, Jim Weirich <> wrote:
    > On Wednesday 13 July 2005 02:15 am, Tim Shadel wrote:
    > > Hi,
    > >
    > > I'm new to Ruby, and gem is hanging when it attempts to update the gem
    > > source index (which happens every time I try to install anything,
    > > obviously).

    > [...]
    > > >gem --debug --backtrace install rails

    > [...]
    > > Exception `TypeError' at
    > > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/remote_installer.rb:222 -
    > > incompatible marshal file format (can't be read)
    > > format version 4.8 required; 45.45 given
    > > Updating Gem source index for: http://gems.rubyforge.org

    >=20
    > It is actually working as intended, except for the hang during the source
    > index update. Gem detects that loading your cache failed (incompatible
    > marshal format), so it attempts to download the source index.
    >=20
    > You can just blow away the cache file. It is named "source_cache" in the
    > directory returned by the command 'gem env gempath'. If the `gem env
    > gempath` directory is protected, you may also have another copy of the ca=

    che
    > in $HOME/.gem.
    >=20
    > Blowing it away will get rid of the marshal file format error. I don't k=

    now
    > if it will solve the download problem or not.
    >=20
    > --
    > -- Jim Weirich http://onestepback.org
    > -----------------------------------------------------------------
    > "Beware of bugs in the above code; I have only proved it correct,
    > not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
    >=20
    >
     
    Tim Shadel, Jul 23, 2005
    #1
    1. Advertising

  2. Do you happen to have zonealarm or some other personal firewall installed.
    The behaviour you are having seems to be one that have been reported previously
    causing by ZA.

    - Ville

    Tim Shadel <> writes:

    > Well, I tried deleting the cache and that didn't work. So I dug in
    > and tried to find the call that was hanging. I eventually traced it
    > down to the TCPSocket.write call inside the HTTP module. Here's a
    > snippet from irb that shows the problem:
    >
    > C:\>irb
    > irb(main):001:0> require 'socket'
    > => true
    > irb(main):002:0> sock = TCPSocket.new("gems.rubyforge.org", 80)
    > => #<TCPSocket:0x2d3c960>
    > irb(main):003:0> sock.write "GET /yaml.Z HTTP/1.1\r\nHost:
    > gems.rubyforge.org\r\n\r\n"
    >
    > (Hangs)
    >
    > I also tried to write a small script to show the problem.
    >
    > -------
    > require 'socket'
    >
    > hostname = ARGV[0]
    > puts "Making socket to #{hostname}"
    > sock = TCPSocket.new(hostname, 80)
    > mesg = "GET /yaml.Z HTTP/1.1\r\nHost: #{hostname}\r\n\r\n"
    > puts "writing to socket #{hostname}: " + mesg
    > sock.write mesg
    > puts "Wow, no hang!"
    > -----
    >
    > Here's the output:
    >
    > ------
    > C:\>ruby test.rb google.com
    > Making socket to google.com
    > writing to socket google.com: GET /yaml.Z HTTP/1.1
    > Host: google.com
     
    Ville Mattila, Jul 24, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesper Olsen

    TCPSocket & $SAFE=1

    Jesper Olsen, Jul 31, 2003, in forum: Ruby
    Replies:
    2
    Views:
    141
    Jesper Olsen
    Aug 1, 2003
  2. Bjarke Bruun

    TCPSocket hangs after ctrl-c

    Bjarke Bruun, Jan 16, 2005, in forum: Ruby
    Replies:
    8
    Views:
    245
    Bjarke Bruun
    Jan 16, 2005
  3. Eric Haase
    Replies:
    0
    Views:
    151
    Eric Haase
    Apr 22, 2006
  4. Austin 7873
    Replies:
    5
    Views:
    218
    Eric Hodel
    Jan 27, 2007
  5. yspro
    Replies:
    2
    Views:
    452
    Simon Krahnke
    Apr 6, 2013
Loading...

Share This Page