Access to the webpage was denied on chrome

While working hard at getting an application up and running for a lunch tomorrow, I ran into this annoying screen:

Access to the webpage was denied
Not really reading the message fully, I thought maybe my web server is throwing some sort of error that was telling chrome to stop the request. Quick google for “Access to the webpage was denied passenger” didn’t really return anything useful, however then I remembered that I switched to Pow a while back, so I google again for “Access to the webpage was denied pow” but that was even less useful.

So I re-read the message and followed the included link from the message and found this:

Chrome net internals httpThrottling
Unchecking the checkbox removed this feature.

Why this happens

Well it seems that chrome has a built-in DDoS protection, meaning that if a server returns a 500 type error, and you keep refreshing the page to see if it has been fix, chrome will actually stop you for a few second (The exact delay is based on how many times you’ve attempted to access the page “delay = initial_backoff * multiply_factor^(effective_failure_count - 1) * Uniform(1 - jitter_factor, 1]“. Get more info at: http://dev.chromium.org/throttling). This intern stops you from putting extra load on the server while (hopefully) the app is getting fixed.

Why this is an issue for me

Now I think it’s great that chrome attempts to stop (probably unintentional) DDoS attacks, but it should really ensure that local requests don’t fall under that protection. I am a developer and I’m trying to fix a local app, which is throwing a 500 error, and I refresh frequently to see if I’ve been able to fix it but when I am delayed before able to see my results, it’s just very unproductive, especially when the delay gets longer with the increasing number of refreshes.

That’s just my thoughts on this. I’ve already let the Chrome team know about this issue. Let me know if you’ve had a similar experience.

UPDATE (Nov 2, 2012)

I just got an email from Jói on the Google Chrome team and he says:

From version 13 onwards, Chrome should not throttle any requests to localhost or its many aliases (localhostv6, 127.0.0.1, ::1 and so forth).  You can check your version by typing about:version into the address bar, but it’s highly likely you are on 14 or later.

On the other hand, it is very difficult for Chrome to distinguish that a domain name or IP address other than the ones universally recognized as being the local loopback address actually points to the local server.

And so it seems because I’m using Pow and my URLs look like http://myapp.dev, chrome is unable to determine if this is a local request and therefore kicks in the DDoS prevention.

Learn More

Wicked_PDF working in Rails 3.1

I recently updated one of my apps to Rails 3.1 and found that my PDF generating tests were failing because they were unable to find the CSS or images to use in the PDF.

So I started playing around, and here is what I got:

In your app, add a new initializer (or edit your existing wicked_pdf.rb initializer) and put the following:

As you can see in the code, I also replaced the background urls with correct references, this is assuming that you’re keeping your CSS images in the same location as your normal images (which I don’t see a reason why not but of course you can always tweak the script)

Possible Issues

Pow.cx

I had one issue with my generated PDF using pow.cx, my CPU would jump to 100% (on the pow process) and the page would timeout. After upgrading to the latest version of pow (0.3.2) using this command:

curl get.pow.cx | sh

I was able to see my PDFs without an issue.

Additional Sources:

http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/

https://github.com/mileszs/wicked_pdf/issues/48

Learn More

Cucumber visiting pages using different formats

Ever wonder how you can write a cucumber test that would test how your web app responds to a different format, something like JSON or XML?
I was trying to do the following:

Background:
 Given I am logged in
 And there is the following feeds:
 | title | body | category |
 | first feed | something good | default |
 | second feed | even better | notice |
 | 3rd feed | something awesome | notice |

Scenario: Reading feeds via json
 When I go to the feeds page using json
 And I should see a json file
 And I should see 3 feeds in the json

Running this code I would get a “Can’t find mapping from “the feeds page using json” to a path.

Trying to figure out how I can do this, I tried to write a new step, like this:

When %r{^I go to the (w+) page using (w+)$} do |page, format|...

but this resulted in: Ambiguous match of “I go to the feeds page using json”

So, I posted the question on StackOverFlow and it seems everyone was thinking the same way I was.

I continued playing  with this idea and here is how I solved the problem:

Modifying the paths.rb file, I changed (Changes are in bold)

def path_to(page_name)
    # Split out format if page_name includes ' using '
    # Example: When I go to the accounts page using json
    page_name, format = page_name.split(' using ')
    case page_name

    when /the homes?page/
      '/'
    when /the new account page/
      #pass format
      new_account_path(:format => format)

    else
      begin
        page_name =~ /the (.*) page/
        path_components = $1.split(/s+/)
        # Also make sure to pass format to the 'guessed' path
        self.send(path_components.push('path').join('_').to_sym, :format => format)
      rescue Object => e
        raise "Can't find mapping from "#{page_name}" to a path.n" +
          "Now, go and add a mapping in #{__FILE__}"
      end
    end
  end
end

This way I don’t have to modify anything else in my features and everything just works.

Learn More

RVM install ruby-1.8.7-p330 fails

Today I’m thinking of getting back into so good old work and I read there is a new patch to Ruby, version p330. So I figure that RVM (Ruby Version Manager) being so easy and quick to update, I’d do the good old “rvm get head, rvm reload, rvm update 1.8.7″ and I’m off to the races.

Well it wasn’t quite as simple. I ended up with an error:
ruby-1.8.7-p330 - #fetching
ruby-1.8.7-p330 - #extracting ruby-1.8.7-p330 to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #extracted to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #configuring
ruby-1.8.7-p330 - #compiling
Error running 'make ', please read /Users/andrew/.rvm/log/ruby-1.8.7-p330/make.log
There has been an error while running make. Halting the installation.

When I looked into the the make.log, It had this to say:
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: error: (Each undeclared identifier is reported only once
readline.c:730: error: for each function it appears in.)

So, I figured this was going to take too long to deal with, and moved on to working on my projects. That is till I opened up my project and and did a “rvm 1.8.7@rails3″ and it come up with:
warn: ruby ruby-1.8.7-p330 is not installed.
To install do: 'rvm install ruby-1.8.7-p330'

Great! Now I can’t upgrade, and I can’t work with what I have!

Long story short, I figured out that I was missing readline (now I’m sure I’ve installed in a long while ago, but I think I was missing the latest version). Also, rvm install readline resulted in an “Unrecognized command line argument: ‘readline’ ( see: ‘rvm usage’ )

Turns out RVM updated it’s command to install readline to:
rvm package install readline

Update: (Nov 10, 2011)
If you’re using a newer version of RVM, package has been renamed to pkg, so the command to install readline would be:
rvm pkg install readline

However this didn’t fix my install issue, still got the same error. Luckily I found a post that pointed out that my rvm may not know where readline is (odd, as I used rvm to install readline). Running this command allowed me to install it correctly:
rvm install 1.8.7 -C –with-readline-dir=/Users/andrew/.rvm/usr
[Notice: 'andrew' is my username on my mac, yours might be different]

rvm install 1.8.7 -C --with-readline-dir=$rvm_path/usr

Like always, I’m hoping this helps some people out.

Let me know if you have any issues.

Learn More

OSX 10.6.5 breaks Apachectl

Trying to run:
sudo apachectl restart

Are you getting:
/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

Edit your /usr/sbin/apachectl on line 65 from:

ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"

to:

ULIMIT_MAX_FILES=""

and try again. It should now be working agian

For more information checkout Deversus

Learn More

Blog’s back up! (and a little update about Anlek Consulting)

I’m happy to say that the blog is back!

Sorry for how long we were down but Anlek Consulting has moved offices and the local server (which was running this blog) was taken down and couldn’t be brought back up. So now we have a new home which should give us a better up time.

A little update on what’s going on at Anlek Consulting. I (Andrew) will be doing a trip around Canada and the USA, hoping to be working on the road with my cell phone and free wifi spots. In light of this, I’m going to probably blog a bit more about the challenges and adventures of working on the road. Stay tuned for some fun posts!

Learn More

Stripping ASCII colour from a ruby string

I spent a few good hours trying to figure out how to strip a coloured ruby string:

Coloured Ruby String

which comes out as this:

>> p t
"2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"
=> nil

Now I tried to gsub the string and remove the colour using a RegEx like this:

> t.gsub(/\e[(d+)m/, "")
=> "2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"

But as you can see, nothing changed. After reading a whole lot of docs on Ruby, Googling around and reading the Ruby String class I came to this conclusion:

>> b = "e[33m"
=> "e[33m"
>> b.each_byte{|c| puts c}
27
91
51
51
109
=> "e[33m"
>> "" << 27 #The only way I know how to add ASCII codes to string
=> "e"

Now what this allowed me to do is figured out the ASCII code for the e character. However because normally you escape the back slash on regular expressions, once I figured out e was a valid character, I got this:

>> "e[33m".gsub(/e[(d+)m/, '')
=> ""

I hope this saves someone a few hours!

Learn More