imanel/websocket-rack

Undefined method `backend' for nil:nilClass

nilclass opened this issue · 6 comments

This is being thrown, if you require 'rack/websocket' before loading 'thin'.
I'm not sure, but I think the aliasing in the thin extension is going wrong.

Anyway, solution is easy: first load thin, then load websocket-rack!
Nevertheless, this is the second time that I scooped through websocket-rack code to figure out what was wrong, so this issue is partly a reminder for myself :)

It's because of WebSocket-Rack selecting backend basing on available servers. So if you don't have any known server loaded then it will throw error. Closing

Well, but with Thin being the only supported server right now, it could just load it :) Or do some magic to make sure, thin is loaded completely before the thin extensions are.

But if you call

thin -R config.ru start

then BEFORE websocket-rack will be loaded thin will finish loading. Then in what configuration you have problem with loading thin?

I'm not using the thin command, but starting thin within a reactor that has other stuff running as well.

Then it's up to you to check if Thin is already loaded. I can't force loading Thin, because backend is selected by checking if Thin is loaded. If in future I will add new backends then all apps(including your) will just break because thin will stop being auto-loaded.
I will mention in readme that you need first load thin before loading websocket-rack if you do custom setup. Thanks for mentioning it!

I'm not suggesting to load thin automatically. Just the error message is a bit confusing. However, as mentioned earlier, the existence of this issue already fixes it, as whoever is having that error will just be pointed here by google: http://www.google.com/search?q=%22Undefined+method+%60backend%27+for+nil:nilClass%22