THRIFT-2080 C# multiplex processor does not catch IOException

Patch: Jens Geyer


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

Branch: refs/heads/master
Commit: 6b9e1c6a87d745c224f6737b07b3ed7d72fcd6e0
Parents: ee353e6
Author: Jens Geyer <[email protected]>
Authored: Sat Jul 6 09:29:19 2013 +0200
Committer: Jens Geyer <[email protected]>
Committed: Sat Jul 6 09:30:31 2013 +0200

----------------------------------------------------------------------
 .../src/Protocol/TMultiplexedProcessor.cs       | 79 +++++++++++---------
 1 file changed, 45 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/6b9e1c6a/lib/csharp/src/Protocol/TMultiplexedProcessor.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Protocol/TMultiplexedProcessor.cs 
b/lib/csharp/src/Protocol/TMultiplexedProcessor.cs
index 29fac9e..4ce8d62 100644
--- a/lib/csharp/src/Protocol/TMultiplexedProcessor.cs
+++ b/lib/csharp/src/Protocol/TMultiplexedProcessor.cs
@@ -25,6 +25,7 @@ using System;
 using System.Text;
 using Thrift.Transport;
 using System.Collections.Generic;
+using System.IO;
 
 namespace Thrift.Protocol 
 {
@@ -102,46 +103,56 @@ namespace Thrift.Protocol
                 message header.  This pulls the message "off the wire", which 
we'll
                 deal with at the end of this method. */
 
-            TMessage message = iprot.ReadMessageBegin();
-
-            if ((message.Type != TMessageType.Call) && (message.Type != 
TMessageType.Oneway)) 
+            try
             {
-                Fail( oprot, message, 
-                      TApplicationException.ExceptionType.InvalidMessageType, 
-                      "Message type CALL or ONEWAY expected");
-                return false;
-            }
+                TMessage message = iprot.ReadMessageBegin();
+
+                if ((message.Type != TMessageType.Call) && (message.Type != 
TMessageType.Oneway))
+                {
+                    Fail(oprot, message,
+                          
TApplicationException.ExceptionType.InvalidMessageType,
+                          "Message type CALL or ONEWAY expected");
+                    return false;
+                }
+
+                // Extract the service name
+                int index = 
message.Name.IndexOf(TMultiplexedProtocol.SEPARATOR);
+                if (index < 0)
+                {
+                    Fail(oprot, message,
+                          TApplicationException.ExceptionType.InvalidProtocol,
+                          "Service name not found in message name: " + 
message.Name + ". " +
+                          "Did you forget to use a TMultiplexProtocol in your 
client?");
+                    return false;
+                }
+
+                // Create a new TMessage, something that can be consumed by 
any TProtocol
+                string serviceName = message.Name.Substring(0, index);
+                TProcessor actualProcessor;
+                if (!ServiceProcessorMap.TryGetValue(serviceName, out 
actualProcessor))
+                {
+                    Fail(oprot, message,
+                          TApplicationException.ExceptionType.InternalError,
+                          "Service name not found: " + serviceName + ". " +
+                          "Did you forget to call RegisterProcessor()?");
+                    return false;
+                }
+
+                // Create a new TMessage, removing the service name
+                TMessage newMessage = new TMessage(
+                        message.Name.Substring(serviceName.Length + 
TMultiplexedProtocol.SEPARATOR.Length),
+                        message.Type,
+                        message.SeqID);
+
+                // Dispatch processing to the stored processor
+                return actualProcessor.Process(new 
StoredMessageProtocol(iprot, newMessage), oprot);
 
-            // Extract the service name
-            int index = message.Name.IndexOf(TMultiplexedProtocol.SEPARATOR);
-            if (index < 0) {
-                Fail( oprot, message, 
-                      TApplicationException.ExceptionType.InvalidProtocol,
-                      "Service name not found in message name: " + 
message.Name + ". "+
-                      "Did you forget to use a TMultiplexProtocol in your 
client?");
-                return false;
             }
-
-            // Create a new TMessage, something that can be consumed by any 
TProtocol
-            string serviceName = message.Name.Substring(0, index);
-            TProcessor actualProcessor;
-            if( ! ServiceProcessorMap.TryGetValue(serviceName, out 
actualProcessor))
+            catch (IOException)
             {
-                Fail( oprot, message, 
-                      TApplicationException.ExceptionType.InternalError,
-                      "Service name not found: " + serviceName + ". "+ 
-                      "Did you forget to call RegisterProcessor()?");
-                return false;
+                return false;  // similar to all other processors
             }
 
-            // Create a new TMessage, removing the service name
-            TMessage newMessage = new TMessage(
-                    message.Name.Substring(serviceName.Length + 
TMultiplexedProtocol.SEPARATOR.Length),
-                    message.Type,
-                    message.SeqID);
-
-            // Dispatch processing to the stored processor
-            return actualProcessor.Process(new StoredMessageProtocol(iprot, 
newMessage), oprot);
         }
 
         /**

Reply via email to