thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Cipov <>
Subject JAVA Thrift library: ___currentMethod statefull variable in async mode
Date Tue, 29 Apr 2014 20:43:43 GMT
I have code like this:TNonblockingTransport transport = new TNonblockingSocket("",
9160, 10000);TAsyncClientManager clientManager = new TAsyncClientManager();TProtocolFactory
protocolFactory = new TBinaryProtocol.Factory();
//generated thrift clientZipkinCollector.AsyncClient c = new ZipkinCollector.AsyncClient(
protocolFactory, clientManager, transport);//calling methods in other threadsc.Log....
I am using async client with nio support (libthrift 0.9.1). I was looking inside the code
and I was surprised about ___currentMethod in
My first question is the purpose of this variable. 
If it is a check to serialize reads and writes to NIO socket than you have a bug there. In
this case you have unprotected critical section on ___currentMethod. It can be mutated from
two threads - one is Selector thread in TAsyncClientManager and the second one is main thread
calling generated thrift protocol method (in this case Log)
public void Log(List<LogEntry> messages, org.apache.thrift.async.AsyncMethodCallback
resultHandler) throws org.apache.thrift.TException { checkReady(); Log_call method_call =
new Log_call(messages, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod
= method_call; //<------mutating;}
This can lead to unpredictable results.
Can some maintainer confirm this ? I would fill you a bug but at first I want to be sure that
I did not missed something crucial.
Either way you should really reconsider using mutable variables in asynchronous environment.
This can lead to serious mess.

Peter CipovJánošík
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message