Repository: thrift
Updated Branches:
  refs/heads/master 55cd520ed -> a6b328f12


THRIFT-2354 Connection errors can lead to case_clause exceptions

Patch: Anthony Molinaro


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/a6b328f1
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/a6b328f1
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/a6b328f1

Branch: refs/heads/master
Commit: a6b328f12a1f0962bf7841e496cf8494ed68e71f
Parents: 55cd520
Author: Jens Geyer <je...@apache.org>
Authored: Tue Mar 18 23:51:23 2014 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Tue Mar 18 23:51:23 2014 +0200

----------------------------------------------------------------------
 lib/erl/src/thrift_binary_protocol.erl | 14 +++++++++-----
 lib/erl/src/thrift_client.erl          | 25 ++++++++++++++-----------
 lib/erl/src/thrift_client_util.erl     |  9 ++++++---
 3 files changed, 29 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/a6b328f1/lib/erl/src/thrift_binary_protocol.erl
----------------------------------------------------------------------
diff --git a/lib/erl/src/thrift_binary_protocol.erl 
b/lib/erl/src/thrift_binary_protocol.erl
index 800fd8e..85abb62 100644
--- a/lib/erl/src/thrift_binary_protocol.erl
+++ b/lib/erl/src/thrift_binary_protocol.erl
@@ -333,11 +333,15 @@ parse_factory_options([{strict_write, Bool} | Rest], 
Opts) when is_boolean(Bool)
 new_protocol_factory(TransportFactory, Options) ->
     ParsedOpts = parse_factory_options(Options, #tbp_opts{}),
     F = fun() ->
-                {ok, Transport} = TransportFactory(),
-                thrift_binary_protocol:new(
-                  Transport,
-                  [{strict_read,  ParsedOpts#tbp_opts.strict_read},
-                   {strict_write, ParsedOpts#tbp_opts.strict_write}])
+               case TransportFactory() of
+                    {ok, Transport} ->
+                        thrift_binary_protocol:new(
+                            Transport,
+                            [{strict_read,  ParsedOpts#tbp_opts.strict_read},
+                             {strict_write, 
ParsedOpts#tbp_opts.strict_write}]);
+                    {error, Error} ->
+                        {error, Error}
+                end
         end,
     {ok, F}.
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/a6b328f1/lib/erl/src/thrift_client.erl
----------------------------------------------------------------------
diff --git a/lib/erl/src/thrift_client.erl b/lib/erl/src/thrift_client.erl
index 5c74adc..c91c3ea 100644
--- a/lib/erl/src/thrift_client.erl
+++ b/lib/erl/src/thrift_client.erl
@@ -96,17 +96,20 @@ read_result(Client = #tclient{protocol = Proto0,
                               seqid    = SeqId},
             Function,
             ReplyType) ->
-    {Proto1, MessageBegin} = thrift_protocol:read(Proto0, message_begin),
-    NewClient = Client#tclient{protocol = Proto1},
-    case MessageBegin of
-        #protocol_message_begin{seqid = RetSeqId} when RetSeqId =/= SeqId ->
-            {NewClient, {error, {bad_seq_id, SeqId}}};
-
-        #protocol_message_begin{type = ?tMessageType_EXCEPTION} ->
-            handle_application_exception(NewClient);
-
-        #protocol_message_begin{type = ?tMessageType_REPLY} ->
-            handle_reply(NewClient, Function, ReplyType)
+    case thrift_protocol:read(Proto0, message_begin) of
+         {Proto1, {error, Reason}} ->
+             NewClient = Client#tclient{protocol = Proto1},
+             {NewClient, {error, Reason}};
+         {Proto1, MessageBegin} ->
+             NewClient = Client#tclient{protocol = Proto1},
+             case MessageBegin of
+                 #protocol_message_begin{seqid = RetSeqId} when RetSeqId =/= 
SeqId ->
+                     {NewClient, {error, {bad_seq_id, SeqId}}};
+                 #protocol_message_begin{type = ?tMessageType_EXCEPTION} ->
+                     handle_application_exception(NewClient);
+                 #protocol_message_begin{type = ?tMessageType_REPLY} ->
+                     handle_reply(NewClient, Function, ReplyType)
+             end
     end.
 
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/a6b328f1/lib/erl/src/thrift_client_util.erl
----------------------------------------------------------------------
diff --git a/lib/erl/src/thrift_client_util.erl 
b/lib/erl/src/thrift_client_util.erl
index c52bb8b..02368bf 100644
--- a/lib/erl/src/thrift_client_util.erl
+++ b/lib/erl/src/thrift_client_util.erl
@@ -56,6 +56,9 @@ new(Host, Port, Service, Options)
     {ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory(
                               TransportFactory, ProtoOpts),
 
-    {ok, Protocol} = ProtocolFactory(),
-
-    thrift_client:new(Protocol, Service).
+    case ProtocolFactory() of
+        {ok, Protocol} ->
+            thrift_client:new(Protocol, Service);
+        {error, Error} ->
+            {error, Error}
+    end.

Reply via email to