Author: dreiss
Date: Tue Jun 10 17:56:49 2008
New Revision: 666409
URL: http://svn.apache.org/viewvc?rev=666409&view=rev
Log:
Fix thrift_server to create transport and protocol inside the processor rather
than inside the acceptor.
This fixes a process and file descriptor leak -- previously, the
thrift_buffered_transport process was linked to the acceptor, which never died.
Modified:
incubator/thrift/trunk/lib/alterl/src/thrift_processor.erl
incubator/thrift/trunk/lib/alterl/src/thrift_server.erl
Modified: incubator/thrift/trunk/lib/alterl/src/thrift_processor.erl
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_processor.erl?rev=666409&r1=666408&r2=666409&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_processor.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_processor.erl Tue Jun 10
17:56:49 2008
@@ -7,17 +7,18 @@
%%%-------------------------------------------------------------------
-module(thrift_processor).
--export([start/4,init/4]).
+-export([start/3,init/3]).
-include("thrift_constants.hrl").
-include("thrift_protocol.hrl").
-record(state, {handler, in_protocol, out_protocol, service}).
-start(IProt, OProt, Service, Handler) ->
- spawn(thrift_processor, init, [IProt, OProt, Service, Handler]).
+start(ProtocolGenerator, Service, Handler) when is_function(ProtocolGenerator,
0) ->
+ spawn(thrift_processor, init, [ProtocolGenerator, Service, Handler]).
-init(IProt, OProt, Service, Handler) ->
+init(ProtocolGenerator, Service, Handler) ->
+ {ok, IProt, OProt} = ProtocolGenerator(),
io:format("Processor started~n"),
loop(#state{in_protocol = IProt,
out_protocol = OProt,
Modified: incubator/thrift/trunk/lib/alterl/src/thrift_server.erl
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_server.erl?rev=666409&r1=666408&r2=666409&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_server.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_server.erl Tue Jun 10 17:56:49
2008
@@ -120,11 +120,15 @@
{ok, Socket} = gen_tcp:accept(ListenSocket),
error_logger:info_msg("Accepted client"),
- {ok, SocketTransport} = thrift_socket_transport:new(Socket),
- {ok, BufferedTransport} = thrift_buffered_transport:new(SocketTransport),
- {ok, Protocol} = thrift_binary_protocol:new(BufferedTransport),
- thrift_processor:start(Protocol, Protocol, Service, Handler),
+ ProtoGen = fun() ->
+ {ok, SocketTransport} =
thrift_socket_transport:new(Socket),
+ {ok, BufferedTransport} =
thrift_buffered_transport:new(SocketTransport),
+ {ok, Protocol} =
thrift_binary_protocol:new(BufferedTransport),
+ {ok, Protocol, Protocol}
+ end,
+
+ thrift_processor:start(ProtoGen, Service, Handler),
receive
refresh ->
error_logger:info_msg("Acceptor refreshing~n"),