You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Arvind Sundararajan <ar...@gmail.com> on 2009/11/26 23:28:23 UTC

Bug in TNonblockingServer.py

I am encountering a bug while using TNonblockingServer on a service
with both oneway requests and synchronous requests.

The implementation seems to start constructing a message in response
to a oneway request and then gives up once it realizes it is a oneway
request

 def ready(self, all_ok, message):

....
        self.message = struct.pack('!i', len(message)) + message
        if len(message) == 0:
            # it was a oneway request, do not write answer
            self.status = WAIT_LEN

On subsequent requests, I then get

[TNonblockingServer.py :113 ] - 2009-11-26 13:58:01,829 - ERROR -
can't read frame size from socket

because len(self.message) == 4 and _read_len is very defensive about
reading only the exact right amount of data from the socket.

My patch is simple and seems to fix the problem:

> svn diff
Index: lib/py/src/server/TNonblockingServer.py
===================================================================
--- lib/py/src/server/TNonblockingServer.py     (revision 884669)
+++ lib/py/src/server/TNonblockingServer.py     (working copy)
@@ -182,6 +182,7 @@
         if len(message) == 0:
             # it was a oneway request, do not write answer
             self.status = WAIT_LEN
+            self.message = ''
         else:
             self.status = SEND_ANSWER
         self.wake_up()

Could someone work with me to commit this?

Arvind.

Re: [PATCH] Re: Bug in TNonblockingServer.py

Posted by Arvind Sundararajan <ar...@gmail.com>.
Done. Created http://issues.apache.org/jira/browse/THRIFT-637


On Fri, Nov 27, 2009 at 8:42 AM, Todd Lipcon <to...@cloudera.com> wrote:
> Hi Arvind,
>
> Can you open a JIRA for this bug if you haven't already?
>
> Thanks,
> -Todd
>
> On Thu, Nov 26, 2009 at 2:41 PM, Arvind Sundararajan <ar...@gmail.com>
> wrote:
>>
>> On Thu, Nov 26, 2009 at 2:28 PM, Arvind Sundararajan <ar...@gmail.com>
>> wrote:
>> > I am encountering a bug while using TNonblockingServer on a service
>> > with both oneway requests and synchronous requests.
>> >
>> > The implementation seems to start constructing a message in response
>> > to a oneway request and then gives up once it realizes it is a oneway
>> > request
>> >
>> >  def ready(self, all_ok, message):
>> >
>> > ....
>> >        self.message = struct.pack('!i', len(message)) + message
>> >        if len(message) == 0:
>> >            # it was a oneway request, do not write answer
>> >            self.status = WAIT_LEN
>> >
>> > On subsequent requests, I then get
>> >
>> > [TNonblockingServer.py :113 ] - 2009-11-26 13:58:01,829 - ERROR -
>> > can't read frame size from socket
>> >
>> > because len(self.message) == 4 and _read_len is very defensive about
>> > reading only the exact right amount of data from the socket.
>> >
>> > My patch is simple and seems to fix the problem:
>> >
>> >> svn diff
>> > Index: lib/py/src/server/TNonblockingServer.py
>> > ===================================================================
>> > --- lib/py/src/server/TNonblockingServer.py     (revision 884669)
>> > +++ lib/py/src/server/TNonblockingServer.py     (working copy)
>> > @@ -182,6 +182,7 @@
>> >         if len(message) == 0:
>> >             # it was a oneway request, do not write answer
>> >             self.status = WAIT_LEN
>> > +            self.message = ''
>> >         else:
>> >             self.status = SEND_ANSWER
>> >         self.wake_up()
>> >
>> > Could someone work with me to commit this?
>> >
>> > Arvind.
>> >
>
>

Re: [PATCH] Re: Bug in TNonblockingServer.py

Posted by Todd Lipcon <to...@cloudera.com>.
Hi Arvind,

Can you open a JIRA for this bug if you haven't already?

Thanks,
-Todd

On Thu, Nov 26, 2009 at 2:41 PM, Arvind Sundararajan <ar...@gmail.com>wrote:

> On Thu, Nov 26, 2009 at 2:28 PM, Arvind Sundararajan <ar...@gmail.com>
> wrote:
> > I am encountering a bug while using TNonblockingServer on a service
> > with both oneway requests and synchronous requests.
> >
> > The implementation seems to start constructing a message in response
> > to a oneway request and then gives up once it realizes it is a oneway
> > request
> >
> >  def ready(self, all_ok, message):
> >
> > ....
> >        self.message = struct.pack('!i', len(message)) + message
> >        if len(message) == 0:
> >            # it was a oneway request, do not write answer
> >            self.status = WAIT_LEN
> >
> > On subsequent requests, I then get
> >
> > [TNonblockingServer.py :113 ] - 2009-11-26 13:58:01,829 - ERROR -
> > can't read frame size from socket
> >
> > because len(self.message) == 4 and _read_len is very defensive about
> > reading only the exact right amount of data from the socket.
> >
> > My patch is simple and seems to fix the problem:
> >
> >> svn diff
> > Index: lib/py/src/server/TNonblockingServer.py
> > ===================================================================
> > --- lib/py/src/server/TNonblockingServer.py     (revision 884669)
> > +++ lib/py/src/server/TNonblockingServer.py     (working copy)
> > @@ -182,6 +182,7 @@
> >         if len(message) == 0:
> >             # it was a oneway request, do not write answer
> >             self.status = WAIT_LEN
> > +            self.message = ''
> >         else:
> >             self.status = SEND_ANSWER
> >         self.wake_up()
> >
> > Could someone work with me to commit this?
> >
> > Arvind.
> >
>

[PATCH] Re: Bug in TNonblockingServer.py

Posted by Arvind Sundararajan <ar...@gmail.com>.
On Thu, Nov 26, 2009 at 2:28 PM, Arvind Sundararajan <ar...@gmail.com> wrote:
> I am encountering a bug while using TNonblockingServer on a service
> with both oneway requests and synchronous requests.
>
> The implementation seems to start constructing a message in response
> to a oneway request and then gives up once it realizes it is a oneway
> request
>
>  def ready(self, all_ok, message):
>
> ....
>        self.message = struct.pack('!i', len(message)) + message
>        if len(message) == 0:
>            # it was a oneway request, do not write answer
>            self.status = WAIT_LEN
>
> On subsequent requests, I then get
>
> [TNonblockingServer.py :113 ] - 2009-11-26 13:58:01,829 - ERROR -
> can't read frame size from socket
>
> because len(self.message) == 4 and _read_len is very defensive about
> reading only the exact right amount of data from the socket.
>
> My patch is simple and seems to fix the problem:
>
>> svn diff
> Index: lib/py/src/server/TNonblockingServer.py
> ===================================================================
> --- lib/py/src/server/TNonblockingServer.py     (revision 884669)
> +++ lib/py/src/server/TNonblockingServer.py     (working copy)
> @@ -182,6 +182,7 @@
>         if len(message) == 0:
>             # it was a oneway request, do not write answer
>             self.status = WAIT_LEN
> +            self.message = ''
>         else:
>             self.status = SEND_ANSWER
>         self.wake_up()
>
> Could someone work with me to commit this?
>
> Arvind.
>

[PATCH] Re: Bug in TNonblockingServer.py

Posted by Arvind Sundararajan <ar...@gmail.com>.
On Thu, Nov 26, 2009 at 2:28 PM, Arvind Sundararajan <ar...@gmail.com> wrote:
> I am encountering a bug while using TNonblockingServer on a service
> with both oneway requests and synchronous requests.
>
> The implementation seems to start constructing a message in response
> to a oneway request and then gives up once it realizes it is a oneway
> request
>
>  def ready(self, all_ok, message):
>
> ....
>        self.message = struct.pack('!i', len(message)) + message
>        if len(message) == 0:
>            # it was a oneway request, do not write answer
>            self.status = WAIT_LEN
>
> On subsequent requests, I then get
>
> [TNonblockingServer.py :113 ] - 2009-11-26 13:58:01,829 - ERROR -
> can't read frame size from socket
>
> because len(self.message) == 4 and _read_len is very defensive about
> reading only the exact right amount of data from the socket.
>
> My patch is simple and seems to fix the problem:
>
>> svn diff
> Index: lib/py/src/server/TNonblockingServer.py
> ===================================================================
> --- lib/py/src/server/TNonblockingServer.py     (revision 884669)
> +++ lib/py/src/server/TNonblockingServer.py     (working copy)
> @@ -182,6 +182,7 @@
>         if len(message) == 0:
>             # it was a oneway request, do not write answer
>             self.status = WAIT_LEN
> +            self.message = ''
>         else:
>             self.status = SEND_ANSWER
>         self.wake_up()
>
> Could someone work with me to commit this?
>
> Arvind.
>