mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
THRIFT-2354 Connection errors can lead to case_clause exceptions
Patch: Anthony Molinaro
This commit is contained in:
parent
55cd520edf
commit
a6b328f12a
@ -333,11 +333,15 @@ parse_factory_options([{strict_write, Bool} | Rest], Opts) when is_boolean(Bool)
|
|||||||
new_protocol_factory(TransportFactory, Options) ->
|
new_protocol_factory(TransportFactory, Options) ->
|
||||||
ParsedOpts = parse_factory_options(Options, #tbp_opts{}),
|
ParsedOpts = parse_factory_options(Options, #tbp_opts{}),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
{ok, Transport} = TransportFactory(),
|
case TransportFactory() of
|
||||||
thrift_binary_protocol:new(
|
{ok, Transport} ->
|
||||||
Transport,
|
thrift_binary_protocol:new(
|
||||||
[{strict_read, ParsedOpts#tbp_opts.strict_read},
|
Transport,
|
||||||
{strict_write, ParsedOpts#tbp_opts.strict_write}])
|
[{strict_read, ParsedOpts#tbp_opts.strict_read},
|
||||||
|
{strict_write, ParsedOpts#tbp_opts.strict_write}]);
|
||||||
|
{error, Error} ->
|
||||||
|
{error, Error}
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
{ok, F}.
|
{ok, F}.
|
||||||
|
|
||||||
|
@ -96,17 +96,20 @@ read_result(Client = #tclient{protocol = Proto0,
|
|||||||
seqid = SeqId},
|
seqid = SeqId},
|
||||||
Function,
|
Function,
|
||||||
ReplyType) ->
|
ReplyType) ->
|
||||||
{Proto1, MessageBegin} = thrift_protocol:read(Proto0, message_begin),
|
case thrift_protocol:read(Proto0, message_begin) of
|
||||||
NewClient = Client#tclient{protocol = Proto1},
|
{Proto1, {error, Reason}} ->
|
||||||
case MessageBegin of
|
NewClient = Client#tclient{protocol = Proto1},
|
||||||
#protocol_message_begin{seqid = RetSeqId} when RetSeqId =/= SeqId ->
|
{NewClient, {error, Reason}};
|
||||||
{NewClient, {error, {bad_seq_id, SeqId}}};
|
{Proto1, MessageBegin} ->
|
||||||
|
NewClient = Client#tclient{protocol = Proto1},
|
||||||
#protocol_message_begin{type = ?tMessageType_EXCEPTION} ->
|
case MessageBegin of
|
||||||
handle_application_exception(NewClient);
|
#protocol_message_begin{seqid = RetSeqId} when RetSeqId =/= SeqId ->
|
||||||
|
{NewClient, {error, {bad_seq_id, SeqId}}};
|
||||||
#protocol_message_begin{type = ?tMessageType_REPLY} ->
|
#protocol_message_begin{type = ?tMessageType_EXCEPTION} ->
|
||||||
handle_reply(NewClient, Function, ReplyType)
|
handle_application_exception(NewClient);
|
||||||
|
#protocol_message_begin{type = ?tMessageType_REPLY} ->
|
||||||
|
handle_reply(NewClient, Function, ReplyType)
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,6 +56,9 @@ new(Host, Port, Service, Options)
|
|||||||
{ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory(
|
{ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory(
|
||||||
TransportFactory, ProtoOpts),
|
TransportFactory, ProtoOpts),
|
||||||
|
|
||||||
{ok, Protocol} = ProtocolFactory(),
|
case ProtocolFactory() of
|
||||||
|
{ok, Protocol} ->
|
||||||
thrift_client:new(Protocol, Service).
|
thrift_client:new(Protocol, Service);
|
||||||
|
{error, Error} ->
|
||||||
|
{error, Error}
|
||||||
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user