Required Sinatra, got '/', did 'hello, world.', requested application root in browser and received nothing.
Literally the barest of bones Sinatra web application will not run as intended on my Mac, after previously working just fine. Page requests do not show up in the console.
I feel this may be due to force quitting an instance of a running application but after searching for a solution on the web I am at a loss and do not know how to rectify the issue.
edit:
require 'sinatra'
get '/' do
'Hello, World.'
end
Problem does persist after a restart
Definitely the correct URL (exactly as I've been working with all day). localhost:4567 as stated in the output when the application is run:
== Sinatra (v1.4.7) has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
edit 2: scorched earth strategy; full reinstall with rvm fixed this issue.
Related
I just setup a custom domain for an AWS API Gateway and set up CNAME entries in Google Domains to redirect to my API Gateway. After maybe 30 minutes of waiting I was able to use Chrome to do a simple GET request to my custom domain that properly forwarded to my API Gateway. I tested in Firefox and it worked fine too.
About 3-4 hours later I came back and tried making the same call using Python requests and it worked the first 3 times then failed.
SSLError: HTTPSConnectionPool(host='ids.references.app', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError("hostname '<my_custom_domain>' doesn't match '*.execute-api.us-east-2.amazonaws.com'")))
At first I thought this was a requests problem, but then I opened up Firefox and it didn't work as well. I tried Edge and the call worked. Then I went back to Python and it worked for a bit, then stopped working. I went back to Firefox and it no longer worked. Then I tried Edge and it no longer worked. Sprinkled in there I've tried Chrome and it has worked every time since it started working. (this order of events is from memory and may be slightly off).
Is this a known issue with updating DNS entries that you get some randomness when things first start until the DNS changes have fully propagated. How would I go about even tracking where the error is occurring? I think that's the most frustrating thing about this, it all seems like magic and there's no obvious point where you get something like server 1.2.3.4 says that cert_1 doesn't go with cert_2 and then later you see something like server 4.5.6.7 says cert_2 is all good (so it works). Would I need to install curl for Windows (Is is possible to make a cURL request and get the route that is taken (similar to traceroute)). Would this even matter though? What if curl was like Chrome, it always worked? Does requests have this functionality (bonus points if someone can show a requests solution)? What about Firefox or Chrome? Or could I use something like wireshark (yikes) that could somehow observe the whole system?
I'm using requests 2.25.1 and Python 3.8.5 on Windows 10 and I believe the latest versions of Edge and Firefox.
I have a test that uses OAuth2 gem to make make an HTTP request:
token = client.auth_code.get_token( code, redirect_uri:redirect_uri )
Capybara does not seem to be running the Rails app as a server:
Faraday::ConnectionFailed:
Connection refused - connect(2) for "localhost" port 3000
Here is the config:
Capybara.app_host = "http://localhost:3000"
Capybara.run_server = true
Capybara.server_port = 3000
Capybara.register_driver :rack_test do |app|
Capybara::RackTest::Driver.new app,
follow_redirects:false
end
Various docs seem to suggest that the above config will run the app as a server, but it does not seem to be the case.
How to run Capybara against a server so that the server responds to HTTP requests?
EDIT: After digging in the Capybara code, it seems that different drivers have different servers. Working with Poltergeist. So perhaps Poltergeist doesn't support running a server.
As usual, a small detail was overlooked.
The spec must be tagged as :js. Otherwise it uses Rack::Test and the server is not started.
I have a proxy set up and running completely fine on my local host. I can connect to the proxy completely fine running this code.
Net::HTTP::Proxy('http://localhost', 1234).start #do whatever I want after this point
I can connect to it through a browser completely fine, however when I go to run it on mechanize it completely fails. Here's the code.
require 'mechanize'
agent=Mechanize.new
agent.set_proxy('localhost', 1234)
agent.get('http://google.com') #or any website for that matter
Here's the error I get back
Net::HTTP::Persistent::Error: too many connection resets (due to end of file reached - EOFError) after 0 requests on 22249020, last used 1376802493.5352573 seconds ago
I've read that the versions after 1.0.0 have difficulties connecting to http proxies, but I need to and I'm currently running version 2.7.2. Is there anything I can do to connect to a proxy.
Some proxies can't handle persistent connections (keep-alive). You need to make sure to use a HTTP/1.1-aware proxy.
What version of Ruby are you running? I have this issue with Ruby 2.1.5 and Mechanize, but not with Ruby 1.9.3.
Presumably you've resolved your problem, but for anyone else who might end up here, downgrading to Ruby 1.9.3 might be a workaround.
I am attempting to deploy a Sinatra streaming SSE response application on the Cedar stack. Unfortunately while it works perfectly in development, once deployed to Heroku the callback or errback never get called when a connection is called, leading to the connection pool getting filled up with stale connections (that never time out because data is still being sent to them on the server side.)
Relvant info from the Heroku documentation:
Long-polling and streaming responses
Cedar supports HTTP 1.1 features such as long-polling and streaming responses. An application has an initial 30 second window to respond with a single byte back to the client. However, each byte transmitted thereafter (either received from the client or sent by your application) resets a rolling 55 second window. If no data is sent during the 55 second window, the connection will be terminated.
If you’re sending a streaming response, such as with server-sent events, you’ll need to detect when the client has hung up, and make sure your app server closes the connection promptly. If the server keeps the connection open for 55 seconds without sending any data, you’ll see a request timeout.
This is exactly what I would like to do -- detect when the client has hung up, and close the connection promptly. However, something about the Heroku routing layer seems to prevent Sinatra from detecting the stream close event as it would normally.
Some sample code that can be used to replicate this:
require 'sinatra/base'
class MyApp < Sinatra::Base
set :path, '/tmp'
set :environment, 'production'
def initialize
#connections = []
EM::next_tick do
EM::add_periodic_timer(1) do
#connections.each do |out|
out << "connections: " << #connections.count << "\n"
end
puts "*** connections: #{#connections.count}"
end
end
end
get '/' do
stream(:keep_open) do |out|
#connections << out
puts "Stream opened from #{request.ip} (now #{#connections.size} open)"
out.callback do
#connections.delete(out)
puts "Stream closed from #{request.ip} (now #{#connections.size} open)"
end
end
end
end
I've put a sample app up at http://obscure-depths-3413.herokuapp.com/ using this code that illustrates the problem. When you connect, the amount of connections will increment, but when you disconnect they never go down. (Full source of demo with Gemfile etc is at https://gist.github.com/mroth/5853993)
I'm at wits end trying to debug this one. Anyone know how to fix it?
P.S. There appears to have been a similar bug in Sinatra but it was fixed a year ago. Also this issue only occurs on production in Heroku, but works fine when run locally.
P.S.2. This occurs when iterating over the connections objects as well, for example adding the following code:
EM::add_periodic_timer(10) do
num_conns = #connections.count
#connections.reject!(&:closed?)
new_conns = #connections.count
diff = num_conns - new_conns
puts "Purged #{diff} connections!" if diff > 0
end
Works great locally, but the connections never appear as closed on Heroku.
An update: after working directly with the Heroku routing team (who are great guys!), this is now fixed in their new routing layer, and should work properly in any platform.
I would do this check by hand sending, in a periodic time, alive signal where the client should respond if the message was received.
Please, look at this simple chat implementation https://gist.github.com/tlewin/5708745 that illustrate this concept.
The application communicates with the client using a simple JSON protocol. When the client receive the alive: true message, the application post back a response and the server store the last communication time.
My aim is to do some automated testing over HTTP and HTTPS/SSL, via Rack, without recourse to a proxy server setup or anything like that. I have a gem that I want to test and I'd like for others to be able to run tests on too, so I'd like it to be as self contained as possible.
The code for App runs fine when run on it's own, so it's not included here, the problem is with the Rack part.
I'd like to do something like this:
app = Rack::Builder.app do
map "/" do
Rack::Handler::WEBrick.run App, Port: 3000
end
map "/ssl" do
Rack::Handler::WEBrick.run App, Port: 3001 # more options for SSL here...
end
end
run app
I've tried several combinations of the code above, like:
http = Rack::Builder.app do
map "/" do
run App
end
end
https = Rack::Builder.app do
map "/ssl" do
run App
end
end
Rack::Handler::WEBrick.run http, Port: 3000
Rack::Handler::WEBrick.run https, Port: 3001 # more options for SSL here...
With the two server setup up I tend to get one server run on the first port listed, then on interrupt it will run the second server on the next port listed - and then, on the next interrupt, either another server on 9292 or it shuts down.
I'm obviously doing something not quite right.
This is quite close, but ends up running the two servers via two different command line commands:
Starting thin server on different ports
Any help is much appreciated.
Current Thin does not support this -- I checked the source code.
Thin v2 is still pre-release, but the config code looks like it supports this via declaring multiple listeners in the config file.
But Thin v2 is still alpha software.
You can also switch to another server like Unicorn that does explicitly support binding to multiple ports or addresses.