Skip to content

Instantly share code, notes, and snippets.

@GUI
Created March 10, 2011 04:11
Show Gist options
  • Save GUI/863562 to your computer and use it in GitHub Desktop.
Save GUI/863562 to your computer and use it in GitHub Desktop.
Multiple Typhoeus::Request PUT requests hanging when connecting to WEBrick server
require "rubygems"
require "sinatra"
set :server, "thin"
set :port, "4568"
put "/" do
"Hi"
end
require "rubygems"
require "sinatra"
set :server, "webrick"
set :port, "4567"
put "/" do
"Hi"
end
require "rubygems"
require "typhoeus"
Typhoeus::Request.run("http://localhost:4568/", :method => :put, :verbose => true)
Typhoeus::Request.run("http://localhost:4568/", :method => :put, :verbose => true)
# Separate window: ruby server_thin.rb
#
# % curl --version
# curl 7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0c zlib/1.2.5 libidn/1.19
# Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smtp smtps telnet tftp
# Features: IDN IPv6 Largefile NTLM SSL libz
#
# % ruby -v
# ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0]
#
# % ruby test_thin.rb
# * About to connect() to localhost port 4568 (#0)
# * Trying ::1... * Connection refused
# * Trying fe80::1... * Connection refused
# * Trying 127.0.0.1... * connected
# * Connected to localhost (127.0.0.1) port 4568 (#0)
# * 0x1008b6200 is at send pipe head!
# > PUT / HTTP/1.1
# Host: localhost:4568
# Accept: */*
# Accept-Encoding: deflate, gzip
# User-Agent: Typhoeus - http://github.com/dbalatero/typhoeus/tree/master
# Content-Length: 0
# Expect: 100-continue
#
# < HTTP/1.1 200 OK
# < Content-Type: text/html;charset=utf-8
# < Content-Length: 2
# < Connection: keep-alive
# < Server: thin 1.2.8 codename Black Keys
# <
# * Connection #0 to host localhost left intact
# * Re-using existing connection! (#0) with host localhost
# * Connected to localhost (127.0.0.1) port 4568 (#0)
# * 0x1008b6200 is at send pipe head!
# > PUT / HTTP/1.1
# Host: localhost:4568
# Accept: */*
# Transfer-Encoding: chunked
# User-Agent: Typhoeus - http://github.com/dbalatero/typhoeus/tree/master
# Expect: 100-continue
#
# < HTTP/1.1 200 OK
# < Content-Type: text/html;charset=utf-8
# < Content-Length: 2
# < Connection: keep-alive
# < Server: thin 1.2.8 codename Black Keys
# <
# * Connection #0 to host localhost left intact
# * Expire cleared
require "rubygems"
require "typhoeus"
Typhoeus::Request.run("http://localhost:4567/", :method => :put, :verbose => true)
Typhoeus::Request.run("http://localhost:4567/", :method => :put, :verbose => true)
# Separate window: ruby server_webrick.rb
#
# % curl --version
# curl 7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0c zlib/1.2.5 libidn/1.19
# Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smtp smtps telnet tftp
# Features: IDN IPv6 Largefile NTLM SSL libz
#
# % ruby -v
# ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0]
#
# % ruby test_webrick.rb
# * About to connect() to localhost port 4567 (#0)
# * Trying ::1... * 0x1008b6200 is at send pipe head!
# * Trying fe80::1... * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 4567 (#0)
# > PUT / HTTP/1.1
# Host: localhost:4567
# Accept: */*
# Accept-Encoding: deflate, gzip
# User-Agent: Typhoeus - http://github.com/dbalatero/typhoeus/tree/master
# Content-Length: 0
# Expect: 100-continue
#
# < HTTP/1.1 200 OK
# < Connection: Keep-Alive
# < Content-Type: text/html;charset=utf-8
# < Date: Thu, 10 Mar 2011 04:04:00 GMT
# < Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-08-16)
# < Content-Length: 2
# <
# * Connection #0 to host localhost left intact
# * Re-using existing connection! (#0) with host localhost
# * Connected to localhost (127.0.0.1) port 4567 (#0)
# * 0x1008b6200 is at send pipe head!
# > PUT / HTTP/1.1
# Host: localhost:4567
# Accept: */*
# Transfer-Encoding: chunked
# User-Agent: Typhoeus - http://github.com/dbalatero/typhoeus/tree/master
# Expect: 100-continue
#
# * Done waiting for 100-continue
# ^C* Closing connection #0
# /Users/nmuerdte/.rvm/gems/ruby-1.8.7-p302/gems/typhoeus-0.2.4/lib/typhoeus/multi.rb:21:in `multi_perform': Interrupt
# from /Users/nmuerdte/.rvm/gems/ruby-1.8.7-p302/gems/typhoeus-0.2.4/lib/typhoeus/multi.rb:21:in `perform'
# from /Users/nmuerdte/.rvm/gems/ruby-1.8.7-p302/gems/typhoeus-0.2.4/lib/typhoeus/hydra.rb:95:in `run'
# from /Users/nmuerdte/.rvm/gems/ruby-1.8.7-p302/gems/typhoeus-0.2.4/lib/typhoeus/request.rb:177:in `run'
# from test_webrick.rb:5
@mislav
Copy link

mislav commented Apr 2, 2013

Currently struggling with the same issue. I don't make concurrent requests, but occasionally a PUT to Webrick fails if it's the first request to the just-started server. I don't think it's a bug in Typhoeus (0.3.3), but a bug in how Webrick (ruby 1.9.3p194) handles Expect: 100-continue

@lukeasrodgers
Copy link

FWIW I ran into this issue as well, and haphazardly wrote-up my experience/solution here, http://www.lukerodgers.ca/2014/08/fixing-slow-http-puts-with-rails-and-typhoeus/, in case it is useful for anyone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment