From f4761e324ea111d5e26c5c506286cc59306e581a Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 11 Jun 2008 00:56:49 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666409 13f79535-47bb-0310-9956-ffa450edef68 --- lib/alterl/src/thrift_processor.erl | 9 +++++---- lib/alterl/src/thrift_server.erl | 12 ++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/alterl/src/thrift_processor.erl b/lib/alterl/src/thrift_processor.erl index 8e077b80..d89b91c9 100644 --- a/lib/alterl/src/thrift_processor.erl +++ b/lib/alterl/src/thrift_processor.erl @@ -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, diff --git a/lib/alterl/src/thrift_server.erl b/lib/alterl/src/thrift_server.erl index e5c9cf97..a639eb04 100644 --- a/lib/alterl/src/thrift_server.erl +++ b/lib/alterl/src/thrift_server.erl @@ -120,11 +120,15 @@ acceptor(ListenSocket, Service, Handler) {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"), -- 2.17.1