Open localhost url

Hi,

When I call call the below code I get a timeout.

http_object = Net::HTTP.new("localhost", "3000")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)

But when application is running on port 3000 and a copy of the same
application is running on a different port(3001) , then it works fine.

http_object = Net::HTTP.new("localhost", "3001")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)

the code is called from test_controller. is there any way i could call
the url?

···

--
Posted via http://www.ruby-forum.com/.

logs :

Timeout::Error (execution expired):
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:126:in `readline'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:2009:in `read_new'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:1050:in `request'
  app/controllers/secure/documents/irisfli20_controller.rb:123:in
`index'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:543:in `start'
  app/controllers/secure/documents/irisfli20_controller.rb:118:in
`index'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:162:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:95:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:92:in `each'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:92:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:23:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:82:in `start'
  script\server:3

···

--
Posted via http://www.ruby-forum.com/.

Timeout::Error (execution expired):
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
  C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:126:in `readline'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:2009:in `read_new'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:1050:in `request'
  app/controllers/documents/test_controller.rb:123:in `index'
  C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:543:in `start'
  app/controllers/documents/test_controller.rb:118:in `index'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:162:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:95:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:92:in `each'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:92:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:23:in `start'
  C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:82:in `start'
  script\server:3

···

--
Posted via http://www.ruby-forum.com/.

Smp Mp wrote in post #1012463:

the code is called from test_controller. is there any way i could call
the url?

Please realise that Ruby and Rails are not the same thing. This is a
Ruby mailing list - there are separate forums for Rails. Rails is an
application which just happens to be written *in* Ruby.

Your problem is most likely because the Rails development server is
single-threaded by default. That is, you can't process a second request
while you're in the middle of processing the first one. You *can* turn
on multithreading; please ask on the Rails forum how to do it.

···

--
Posted via http://www.ruby-forum.com/\.

Not using Webrick -- that's a single-threaded server, so it can't
respond to your request until it finishes what it's doing -- sending
your request. Which obviously doesn't work too well. :slight_smile:

If you were running something multi-threaded, e.g. multiple unicorns,
Passenger, etc. it would be fine, if architecturally sketchy (IMO).

HTH,

···

On Fri, Jul 22, 2011 at 11:59 AM, Smp Mp <sharnelp@gmail.com> wrote:

When I call call the below code I get a timeout.

http_object = Net::HTTP.new("localhost", "3000")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)

But when application is running on port 3000 and a copy of the same
application is running on a different port(3001) , then it works fine.

http_object = Net::HTTP.new("localhost", "3001")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)

the code is called from test_controller. is there any way i could call
the url?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

I would bet that the server only allows one request at a time, so trying to perform an HTTP request against yourself won't work.

This makes me wonder why you're performing an HTTP request against yourself and not calling yourself internally using ruby.

···

On Jul 22, 2011, at 11:59 AM, Smp Mp wrote:

When I call call the below code I get a timeout.

http_object = Net::HTTP.new("localhost", "3000")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)

But when application is running on port 3000 and a copy of the same
application is running on a different port(3001) , then it works fine.

http_object = Net::HTTP.new("localhost", "3001")
hresp, data =
http_object.get("/documents/wdocs/generatedata?"+query_string ,"", nil)

the code is called from test_controller. is there any way i could call
the url?

Timeout::Error (execution expired):
C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
C:/jruby-1.4.0/lib/ruby/1.8/net/protocol.rb:126:in `readline'
C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:2009:in `read_new'
C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:1050:in `request'
app/controllers/documents/test_controller.rb:123:in `index'
C:/jruby-1.4.0/lib/ruby/1.8/net/http.rb:543:in `start'
app/controllers/documents/test_controller.rb:118:in `index'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:162:in `start'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:95:in `start'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:92:in `each'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:92:in `start'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:23:in `start'
C:/jruby-1.4.0/lib/ruby/1.8/webrick/server.rb:82:in `start'
script\server:3

WEBrick is not a single-threaded server. It can be configured as a single-threaded server but it is not by default:

require 'webrick'
require 'net/http'

s = WEBrick::HTTPServer.new :Port => 8000

count = 0

s.mount_proc '/count' do |req, res|
  count += 1
  res.body = count.to_s
end

s.mount_proc '/' do |req, res|
  Net::HTTP.start 'localhost', 8000 do |http|
    res.body = http.get('/count').body
  end
end

trap 'INT' do s.shutdown end
trap 'TERM' do s.shutdown end

s.start

···

On Jul 22, 2011, at 2:46 PM, Hassan Schroeder wrote:

Not using Webrick -- that's a single-threaded server, so it can't
respond to your request until it finishes what it's doing -- sending
your request. Which obviously doesn't work too well. :slight_smile:

Wouldn't be the first time I was wrong :slight_smile:

But certainly the default Rails configuration *appears* to be single-
threaded. If not, why does that simple test case fail when the same
thing works with e.g. a couple of Unicorns?

···

On Fri, Jul 22, 2011 at 3:48 PM, Eric Hodel <drbrain@segment7.net> wrote:

WEBrick is not a single-threaded server. It can be configured as a single-threaded server but it is not by default:

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

Hassan Schroeder wrote in post #1012506:

But certainly the default Rails configuration *appears* to be single-
threaded.

It is - not because of an inherent limitation of webrick, but because
Rails itself has a global dispatcher lock. This dates from the days when
Rails internals were not thread-safe. They are now, but because your
application may not be thread safe, the global lock remains unless you
give a configuration command to turn it off. Google "rails config
threadsafe"

Normally it doesn't matter in production, because you're running
multiple server processes (e.g. mongrels, passenger workers etc) behind
some sort of proxy, and you only want each one to be handling one
request at a time.

···

--
Posted via http://www.ruby-forum.com/\.

Ah, right, I'd forgotten all about that. Thanks for the correction!

···

On Fri, Jul 22, 2011 at 11:30 PM, Brian Candler <b.candler@pobox.com> wrote:

It is - not because of an inherent limitation of webrick, but because
Rails itself has a global dispatcher lock. This dates from the days when
Rails internals were not thread-safe.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan