merb + thin + unix domain sockets - not working as expected

20 views
Skip to first unread message

Amit

unread,
Oct 22, 2009, 3:19:02 PM10/22/09
to merb, amit....@inventureglobal.com
Hi guys,

I was using merb + mongrel for an api server but that had problems
with clients using persistent connections, thanks to mongrel. So, I
thought of switching to merb + thin as the combo (thin, in particular)
claims to support persistent connections using unix domain sockets.
When I run "merb -a thin", everything works fine except of course
persistent connections and the reason I think is that the command
results in merb and thin communicate through internet sockets rather
than unix domain sockets. So, I went by the suggestions I found on the
net and used following command instead -
merb -a thin -h log/thin.sock -p 4000

I see the following output on the console -
merb : worker (port 4000) ~ Starting Thin at port 4000
merb : worker (port 4000) ~ Using Thin adapter on host log/
thin.sock and port 4000.
merb : worker (port 4000) ~ Successfully bound to port 4000

However, now my client program is not even able to hit the server app;
it dies with "Connection refused" error!! Doing a "netstat -l" on the
server (I'm on Ubuntu) reveals that no process is listening on port
4000, although thin seems to be listening on a unix domain socket.
Here's the output from "netstat -l" -

Proto RefCnt Flags Type State I-
Node Path
unix 2 [ ACC ] STREAM LISTENING 14310 log/
thin.sock-4000

The client is trying to hit the server at port 4000 which is bound to
fail as that port is not being listened on. Any idea what could be
wrong? Am I missing something here?

thanks
Amit



Amit

unread,
Oct 22, 2009, 4:07:11 PM10/22/09
to merb
Just to add...
I'm on Merb 1.1, using Thin 1.2.4 and EventMachine 0.12.8.

Pavel Kunc

unread,
Oct 23, 2009, 10:22:11 AM10/23/09
to merb
Hm... I've never tried to use sockets.

I just use ./bin/merb -athin -p4000

Why you specify socket explicitly?

Pavel

Amit

unread,
Oct 23, 2009, 11:33:37 AM10/23/09
to merb
Hi Pavel,

I need to specify socket to be able to use keep-alive (persistent
connections).
Thin is capable of using keep-alive but only with unix domain sockets.
Hope I'm clear.

thanks
Amit

Pavel Kunc

unread,
Oct 24, 2009, 7:12:59 AM10/24/09
to merb
Heh I should read more carefully your first post. Sorry. Could you
please file the issue to the merb.lighthouse.com? So we can handle it
and it just don't get forgotten :-)

Cheers

Pavel

Jonathan Stott

unread,
Oct 24, 2009, 7:30:47 AM10/24/09
to me...@googlegroups.com
On Fri, 23 Oct 2009 08:33:37 -0700 (PDT)
Amit <a4ami...@gmail.com> wrote:

>
> Hi Pavel,
>
> I need to specify socket to be able to use keep-alive (persistent
> connections).
> Thin is capable of using keep-alive but only with unix domain sockets.
> Hope I'm clear.
>
> thanks
> Amit
>

A unix domain socket is socket which is used only for local connections. It isn't bound to a network port, so not being able to connect to one using the network is to be expected. If thin only supports keep-alive with unix domain sockets, you'll need to put some kind of a proxy in front of it (e.g. nginx) which will actually bind to the network port and allow remote communication. You also need to make sure you're doing things like setting a Content-Length header. I'm not sure, off hand, if merb does this for you.

Regards
Jon

Amit

unread,
Nov 3, 2009, 4:14:05 AM11/3/09
to merb
hi Jon,

Thanks for your response. Actually, I was expecting that Thin would
communicate with Merb on unix domain sockets (to enable back-end keep
alive connections) and still listen for client requests on network
port (4000 in my case). And if you see the console output in my
initial post, it does give an impression that Thin has started
listening on port 4000. And I was surprised to find that port 4000 was
not in use at all!

My main app (which is in production) anyways uses Nginx as a proxy, so
eventually I was targeting to have my Thin+Merb combo behind that (as
you suggested). But I just wanted to test keep alive connections first
before tweaking my production configuration to start proxying specific
requests to the Thin+Merb combo. Sadly, I just figured out that Nginx
doesn't support back-end keep alive connections yet, so that's a major
setback. But still, just for the sake of information that we could use
some day, I would still like to know if it's possible to have Thin
listen for client requests on a network port and communicate with Merb
via unix domain sockets?

I was away so didn't respond for a while, sorry abt that.

thanks
Amit


On Oct 24, 4:30 pm, Jonathan Stott <jonathan.st...@gmail.com> wrote:
> On Fri, 23 Oct 2009 08:33:37 -0700 (PDT)
>
Reply all
Reply to author
Forward
0 new messages