[ 
https://issues.apache.org/jira/browse/HIVE-24694?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

kirby zhou reopened HIVE-24694:
-------------------------------

This patch is not merged to current release 3.1.3

Without this patch, a connection leak will occur when the Sasl handshake times 
out.

When creating HiveConnection with password, openTransport will be called, and 
openTransport will call the following callstack layer by layer.
{code:java}
        at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
        - locked <0x000000073b8638e8> (a java.io.BufferedInputStream)
        at 
org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:127)
        at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
        at 
org.apache.thrift.transport.TSaslTransport.receiveSaslMessage(TSaslTransport.java:178)
        at 
org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:307)
        at 
org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:196)  
{code}
TIOStreamTransport::read will throw 

TTransportException(TTransportException.UNKNOWN, iox) when 

IOException happens.

 

 
{code:java}
try {
  bytesRead = inputStream_.read(buf, off, len);
} catch (IOException iox)
{   
  throw new TTransportException(TTransportException.UNKNOWN, iox); 
}  {code}
 

 

TSaslTransport.open will only call close() at e.getType() == 
TTransportException.END_OF_FILE, it seems be designed.

 
{code:java}
} catch (TTransportException e) {
  /*
   * If there is no-data or no-sasl header in the stream, throw a different
   * type of exception so we can handle this scenario differently.
   */
  if (!readSaslHeader && e.getType() == TTransportException.END_OF_FILE) {
    underlyingTransport.close();
    LOGGER.debug("No data or no sasl data in the stream");
    throw new TSaslTransportException("No data or no sasl data in the stream");
  }
  throw e;
} {code}
 

 

But HiveConnection will never call this.close() or transport.close() when any 
Exception thrown by TSaslClientTransport.open().

And after the constructor fails, the caller has no chance to go to close 
transport.

 

 

 

> Early connection close to release server resources during creating
> ------------------------------------------------------------------
>
>                 Key: HIVE-24694
>                 URL: https://issues.apache.org/jira/browse/HIVE-24694
>             Project: Hive
>          Issue Type: Bug
>          Components: HiveServer2
>            Reporter: Zhihua Deng
>            Assignee: Zhihua Deng
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.0.0-alpha-1
>
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> If exception happens during we try to get the connection from HiveDriver,  
> the opened transport or session may leave unclosed as the connection returned 
> is null, we cannot call the close method to release the server 
> resources(threads, connection quota, etc.), this could make things more worse 
> if the user rearches the connection limit and retries... 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to