Author: mcslee
Date: Tue Oct 14 15:05:11 2008
New Revision: 704714
URL: http://svn.apache.org/viewvc?rev=704714&view=rev
Log:
THRIFT-170: Buffered transports leave data in write buffer on failed flush
Reviewed By: mcslee
Modified:
incubator/thrift/trunk/lib/py/src/transport/TTransport.py
Modified: incubator/thrift/trunk/lib/py/src/transport/TTransport.py
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/py/src/transport/TTransport.py?rev=704714&r1=704713&r2=704714&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/py/src/transport/TTransport.py (original)
+++ incubator/thrift/trunk/lib/py/src/transport/TTransport.py Tue Oct 14
15:05:11 2008
@@ -146,9 +146,11 @@
self.__wbuf.write(buf)
def flush(self):
- self.__trans.write(self.__wbuf.getvalue())
- self.__trans.flush()
+ out = self.__wbuf.getvalue()
+ # reset wbuf before write/flush to preserve state on underlying failure
self.__wbuf = StringIO()
+ self.__trans.write(out)
+ self.__trans.flush()
# Implement the CReadableTransport interface.
@property
@@ -275,6 +277,8 @@
return self.__trans.flush()
wout = self.__wbuf.getvalue()
wsz = len(wout)
+ # reset wbuf before write/flush to preserve state on underlying failure
+ self.__wbuf = StringIO()
# N.B.: Doing this string concatenation is WAY cheaper than making
# two separate calls to the underlying socket object. Socket writes in
# Python turn out to be REALLY expensive, but it seems to do a pretty
@@ -282,4 +286,3 @@
buf = pack("!i", wsz) + wout
self.__trans.write(buf)
self.__trans.flush()
- self.__wbuf = StringIO()