You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Paul Meier <pa...@gmail.com> on 2011/02/14 20:07:01 UTC
Erlang server only works when called from shell?
Hi friends,
Forgive me if I'm missing something obvious, but when I try to run an
Erlang Thrift Server, it works if I run something like:
erl +K true -pa all_your_beams/
And run server:start() from the Erlang command shell.
But if I write a bash wrapper that says something like
erl +K true -pa all_your_beams/ -noshell -run server start
then connecting clients fail, saying Connection Refused, despite there
being a message saying there's a Thrift Service listening on the appropriate
port. This is the case in both the tutorial and my own application. Is
this a known issue? Has anyone else experienced this?
It's not mission-critical, but any help would be appreciated. Thanks
^_^
-Paul
Re: Erlang server only works when called from shell?
Posted by Anthony Molinaro <an...@alumni.caltech.edu>.
Hi,
Thanks for pointing out the problems with compilation, I just checked
in some fixes for those. The problem with just doing -s server is that
the start function does start the server, but the return of the
server start call is a pid which is then ignored. Since that pid is
never linked into the supervision tree it dies. So you get a
connection refused.
What you really want to do is create an otp application, a supervisor
as well as the service which actually starts the server. thrift_erl_skel
used to do this, but looking at it, I found it very out of date. I sort
of updated it, but not super well, as there isn't currently a thrift
plugin for rebar, but if you have a thrift file and you want a server
with supervisor/application check out
https://github.com/djnym/thrift_erl_skel
Not too many instructions, and you'll have to have rebar and thrift
installed to get it to work, but it works for me :)
-Anthony
On Tue, Feb 15, 2011 at 11:26:51AM -0800, Paul Meier wrote:
> Hi,
>
> Thanks for getting back to me. Incidentally, that's exactly what my
> server module looks like. And while my wrapper script was using "erl -run
> server start" as opposed to "erl -s server", neither of them creates a
> server that accepts incoming connections from thrift clients, unless I
> invoke their server:start() from the erlang shell itself, which I found
> pretty bizarre.
>
> I just tried this with a vanilla Thrift install, so unless there's
> some differences in our Erlang VM's, one can probably reproduce it
> themselves by doing the following (assuming everything is built, etc):
>
> 1. Generate the thrift tutorial files with 'thrift -r --gen erl
> tutorial.thrift'.
>
> 2. Correct the errors in client.erl and server.erl: they reference
> different constants than Thrift generates, so 'tutorial_ADD',
> 'tutorial_SUBTRACT' and their ilk should be 'tutorial_Operation_ADD',
> 'tutorial_Operation_SUBTRACT', etc.
>
> 3. Run server.sh, which opens a shell if everything compiled successfully.
> Manually call server:start(), then call client:t(). This opens a Thrift
> server on Port 9999, runs the client, and works fine.
>
> 4. Now edit the 'erl' invocation at the end of server.sh to have '-s server'
> as one of it's flags, and run it again (presuming you killed the previous
> process). This automatically calls server:start(). Call client:t().
> Connection refused.
>
> If you edit the word 'localhost' to '127.0.0.1' in the Ruby client (and
> feed it port 9999), you'll observe the same thing.
>
> I'm completely baffled why the shell would require something like this,
> and I'll email the list if I find anything (I'm sort of new to the platform,
> so I'm reading up on erl(1), boot files, rel files, etc. to see if there's
> some semantic difference on invocation that I'm missing). I just wanted to
> know if this was known, or if I'm doing anything blatantly wrong.
>
> As for thrift_erl_skel, I'm trying to add Thrift to a previously
> existing application, so I haven't looked at it too much for my project.
> But I'll play with the output it generates, see if it helps.
>
> Thanks,
>
> -Paul
>
>
>
> On Mon, Feb 14, 2011 at 9:18 PM, Anthony Molinaro <
> anthonym@alumni.caltech.edu> wrote:
>
> > Hi,
> >
> > What does your start function currently look like? You can probably
> > do something like
> >
> > -module (server).
> > start () ->
> > thrift_socket_server:start ([{port, 12345},
> > {name, ?MODULE},
> > {service, myService_thrift},
> > {handler, ?MODULE},
> > {framed, true},
> > {socket_opts, [{recv_timeout, 60000}]}]).
> >
> > Then you should be able to use
> >
> > % erl -s server
> >
> > in a server. Also you could check out
> >
> > https://github.com/toddlipcon/thrift_erl_skel
> >
> > which will create a skeleton application, supervisor, and service.
> >
> > -Anthony
> >
> > On Mon, Feb 14, 2011 at 11:07:01AM -0800, Paul Meier wrote:
> > > Hi friends,
> > >
> > > Forgive me if I'm missing something obvious, but when I try to run
> > an
> > > Erlang Thrift Server, it works if I run something like:
> > >
> > > erl +K true -pa all_your_beams/
> > >
> > > And run server:start() from the Erlang command shell.
> > >
> > > But if I write a bash wrapper that says something like
> > >
> > > erl +K true -pa all_your_beams/ -noshell -run server start
> > >
> > > then connecting clients fail, saying Connection Refused, despite
> > there
> > > being a message saying there's a Thrift Service listening on the
> > appropriate
> > > port. This is the case in both the tutorial and my own application. Is
> > > this a known issue? Has anyone else experienced this?
> > >
> > > It's not mission-critical, but any help would be appreciated.
> > Thanks
> > > ^_^
> > >
> > > -Paul
> >
> > --
> > ------------------------------------------------------------------------
> > Anthony Molinaro <an...@alumni.caltech.edu>
> >
--
------------------------------------------------------------------------
Anthony Molinaro <an...@alumni.caltech.edu>
Re: Erlang server only works when called from shell?
Posted by Paul Meier <pa...@gmail.com>.
Hi,
Thanks for getting back to me. Incidentally, that's exactly what my
server module looks like. And while my wrapper script was using "erl -run
server start" as opposed to "erl -s server", neither of them creates a
server that accepts incoming connections from thrift clients, unless I
invoke their server:start() from the erlang shell itself, which I found
pretty bizarre.
I just tried this with a vanilla Thrift install, so unless there's
some differences in our Erlang VM's, one can probably reproduce it
themselves by doing the following (assuming everything is built, etc):
1. Generate the thrift tutorial files with 'thrift -r --gen erl
tutorial.thrift'.
2. Correct the errors in client.erl and server.erl: they reference
different constants than Thrift generates, so 'tutorial_ADD',
'tutorial_SUBTRACT' and their ilk should be 'tutorial_Operation_ADD',
'tutorial_Operation_SUBTRACT', etc.
3. Run server.sh, which opens a shell if everything compiled successfully.
Manually call server:start(), then call client:t(). This opens a Thrift
server on Port 9999, runs the client, and works fine.
4. Now edit the 'erl' invocation at the end of server.sh to have '-s server'
as one of it's flags, and run it again (presuming you killed the previous
process). This automatically calls server:start(). Call client:t().
Connection refused.
If you edit the word 'localhost' to '127.0.0.1' in the Ruby client (and
feed it port 9999), you'll observe the same thing.
I'm completely baffled why the shell would require something like this,
and I'll email the list if I find anything (I'm sort of new to the platform,
so I'm reading up on erl(1), boot files, rel files, etc. to see if there's
some semantic difference on invocation that I'm missing). I just wanted to
know if this was known, or if I'm doing anything blatantly wrong.
As for thrift_erl_skel, I'm trying to add Thrift to a previously
existing application, so I haven't looked at it too much for my project.
But I'll play with the output it generates, see if it helps.
Thanks,
-Paul
On Mon, Feb 14, 2011 at 9:18 PM, Anthony Molinaro <
anthonym@alumni.caltech.edu> wrote:
> Hi,
>
> What does your start function currently look like? You can probably
> do something like
>
> -module (server).
> start () ->
> thrift_socket_server:start ([{port, 12345},
> {name, ?MODULE},
> {service, myService_thrift},
> {handler, ?MODULE},
> {framed, true},
> {socket_opts, [{recv_timeout, 60000}]}]).
>
> Then you should be able to use
>
> % erl -s server
>
> in a server. Also you could check out
>
> https://github.com/toddlipcon/thrift_erl_skel
>
> which will create a skeleton application, supervisor, and service.
>
> -Anthony
>
> On Mon, Feb 14, 2011 at 11:07:01AM -0800, Paul Meier wrote:
> > Hi friends,
> >
> > Forgive me if I'm missing something obvious, but when I try to run
> an
> > Erlang Thrift Server, it works if I run something like:
> >
> > erl +K true -pa all_your_beams/
> >
> > And run server:start() from the Erlang command shell.
> >
> > But if I write a bash wrapper that says something like
> >
> > erl +K true -pa all_your_beams/ -noshell -run server start
> >
> > then connecting clients fail, saying Connection Refused, despite
> there
> > being a message saying there's a Thrift Service listening on the
> appropriate
> > port. This is the case in both the tutorial and my own application. Is
> > this a known issue? Has anyone else experienced this?
> >
> > It's not mission-critical, but any help would be appreciated.
> Thanks
> > ^_^
> >
> > -Paul
>
> --
> ------------------------------------------------------------------------
> Anthony Molinaro <an...@alumni.caltech.edu>
>
Re: Erlang server only works when called from shell?
Posted by Anthony Molinaro <an...@alumni.caltech.edu>.
Hi,
What does your start function currently look like? You can probably
do something like
-module (server).
start () ->
thrift_socket_server:start ([{port, 12345},
{name, ?MODULE},
{service, myService_thrift},
{handler, ?MODULE},
{framed, true},
{socket_opts, [{recv_timeout, 60000}]}]).
Then you should be able to use
% erl -s server
in a server. Also you could check out
https://github.com/toddlipcon/thrift_erl_skel
which will create a skeleton application, supervisor, and service.
-Anthony
On Mon, Feb 14, 2011 at 11:07:01AM -0800, Paul Meier wrote:
> Hi friends,
>
> Forgive me if I'm missing something obvious, but when I try to run an
> Erlang Thrift Server, it works if I run something like:
>
> erl +K true -pa all_your_beams/
>
> And run server:start() from the Erlang command shell.
>
> But if I write a bash wrapper that says something like
>
> erl +K true -pa all_your_beams/ -noshell -run server start
>
> then connecting clients fail, saying Connection Refused, despite there
> being a message saying there's a Thrift Service listening on the appropriate
> port. This is the case in both the tutorial and my own application. Is
> this a known issue? Has anyone else experienced this?
>
> It's not mission-critical, but any help would be appreciated. Thanks
> ^_^
>
> -Paul
--
------------------------------------------------------------------------
Anthony Molinaro <an...@alumni.caltech.edu>