简体   繁体   中英

TTransportException without any specific message

I got this exception and it doesn't have any specific message such as "read timeout, "connection refuse" or "connection reset". And this exception doesn't happen usually.

I wonder What is the root cause of this exception?

org.apache.thrift.transport.TTransportException at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132) at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84) at org.apache.thrift.transport.TFramedTransport.readFrame(TFramedTransport.java:129) at org.apache.thrift.transport.TFramedTransport.read(TFramedTransport.java:101) at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84) at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378) at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297) at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:204) at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)

The relevant line in the code says

 if (bytesRead < 0) { 
    throw new TTransportException(TTransportException.END_OF_FILE); 
 } 

The caller was not able to read len bytes from the underlying transport, which usually means that the remote end hung up (closed the connection):

/** 
 * Reads from the underlying input stream if not null. 
 */ 
public int read(byte[] buf, int off, int len) throws TTransportException 
{ 
    if (inputStream_ == null) { 
        throw new TTransportException(TTransportException.NOT_OPEN, "Cannot read from null inputStream"); 
    } 
    int bytesRead; 
    try { 
        bytesRead = inputStream_.read(buf, off, len); 
    } catch (IOException iox) { 
        throw new TTransportException(TTransportException.UNKNOWN, iox); 
    } 
   if (bytesRead < 0) { 
       throw new TTransportException(TTransportException.END_OF_FILE); 
    } 
    return bytesRead; 
} 

For servers, and you don't experience any problems that indicate an issue, that particular one is just how Thrift works.

For clients, as in your example, it seems to indicate that the server closed the connection prematurely (the client waits in TServiceClient.receiveBase() to receive a response).

Most likely reason is some uncaught error on the server end. Another possible source that comes to mind is could be mismatch of protocol/transport stacks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM