You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Dmitriy Kargapolov (JIRA)" <ji...@apache.org> on 2011/04/06 00:09:05 UTC

[jira] [Commented] (THRIFT-1076) Erlang Thrift socket server has a bug that causes java thrift client of framed binary client to throw "out of sequence" exception

    [ https://issues.apache.org/jira/browse/THRIFT-1076?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13016150#comment-13016150 ] 

Dmitriy Kargapolov commented on THRIFT-1076:
--------------------------------------------

Would you please take a look at another version of this fix, it passed sequence id through the thrift processor loop state (which I believe is very suitable for this purpose), and has less extra-argument additions to subsequent calls.
Sincerely...
{code}
diff --git a/src/thrift_processor.erl b/src/thrift_processor.erl
index 4315505..334a74e 100644
--- a/src/thrift_processor.erl
+++ b/src/thrift_processor.erl
@@ -24,7 +24,7 @@
 -include("thrift_constants.hrl").
 -include("thrift_protocol.hrl").

--record(thrift_processor, {handler, protocol, service}).
+-record(thrift_processor, {handler, protocol, service, seqid}).

 init({_Server, ProtoGen, Service, Handler}) when is_function(ProtoGen, 0) ->
     {ok, Proto} = ProtoGen(),
@@ -37,12 +37,14 @@ loop(State0 = #thrift_processor{protocol  = Proto0}) ->
     State1 = State0#thrift_processor{protocol = Proto1},
     case MessageBegin of
         #protocol_message_begin{name = Function,
-                                type = ?tMessageType_CALL} ->
-            {State2, ok} = handle_function(State1, list_to_atom(Function)),
+                                type = ?tMessageType_CALL,
+                                seqid = SeqId} ->
+            {State2, ok} = handle_function(State1#thrift_processor{seqid = SeqId}, list_to_atom(Function)),
             loop(State2);
         #protocol_message_begin{name = Function,
-                                type = ?tMessageType_ONEWAY} ->
-            {State2, ok} = handle_function(State1, list_to_atom(Function)),
+                                type = ?tMessageType_ONEWAY,
+                                seqid = SeqId} ->
+            {State2, ok} = handle_function(State1#thrift_processor{seqid = SeqId}, list_to_atom(Function)),
             loop(State2);
         {error, timeout} ->
             thrift_protocol:close_transport(Proto1),
@@ -169,11 +171,11 @@ handle_error(State, Function, Error) ->
                 type = ?TApplicationException_UNKNOWN}},
     send_reply(State, Function, ?tMessageType_EXCEPTION, Reply).

-send_reply(State = #thrift_processor{protocol = Proto0}, Function, ReplyMessageType, Reply) ->
+send_reply(State = #thrift_processor{protocol = Proto0, seqid = SeqId}, Function, ReplyMessageType, Reply) ->
     {Proto1, ok} = thrift_protocol:write(Proto0, #protocol_message_begin{
                                            name = atom_to_list(Function),
                                            type = ReplyMessageType,
-                                           seqid = 0}),
+                                           seqid = SeqId}),
     {Proto2, ok} = thrift_protocol:write(Proto1, Reply),
     {Proto3, ok} = thrift_protocol:write(Proto2, message_end),
     {Proto4, ok} = thrift_protocol:flush_transport(Proto3),
{code}

> Erlang Thrift socket server has a bug that causes java thrift client of framed binary client to throw "out of sequence" exception
> ---------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1076
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1076
>             Project: Thrift
>          Issue Type: Bug
>          Components: Erlang - Library
>    Affects Versions: 0.5
>         Environment: CentOS5.5, Erlang 13B04, thrift 0.5
>            Reporter: Pascal Qu
>            Assignee: Pascal Qu
>            Priority: Critical
>             Fix For: 0.7
>
>         Attachments: seq.diff, thrift_processor.erl
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Repro step:
> 1) I defined a thrift file like below:
> namespace java com.foo.jabber
> service FrontendService {
>   bool isUserOnline(1:string userId, 2:string userDomain)
> }
> 2) I implemented an erlang thrift server of framed, binary;
> 3) I use a java thrift framed+binary client to talk to the server;
> 4) I always got an exception of "out of sequence" while call isUserOnline(), while the thrift server had responsed to the request.
> After some investigation, i found the field seq of reply's protocol_message_begin is hardcoded as 0 in thrift_processor.erl. I think it should be the save as that of request. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira