Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2950

Avatica DriverVersion.load leaks InputStream, and causing native memory leak

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: avatica-1.13.0
    • Fix Version/s: avatica-1.14.0
    • Component/s: avatica
    • Environment:

      CentOS release 6.9 (Final)

      Description

      Kylin's JDBC Driver(https://github.com/apache/kylin/tree/master/jdbc) is based on Avatica. While using Kylin JDBC Driver, if repeatedly invoking

      //code from Application code.
      Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
      

      , which repeatedly invokes

       

      //code from Kylin JDBC
      DriverVersion version = DriverVersion.load(Driver.class, "org-apache-kylin-jdbc.properties", "Kylin JDBC Driver", "unknown version", "Kylin", "unknown version");
      

      Then the native memory leak can be observed, see attached memory profile diagram(from jeprof).

      And the leaking stack trace is below.

              at java.util.zip.Inflater.inflate
              at java.util.zip.InflaterInputStream.read()
              at java.io.FilterInputStream.read(FilterInputStream.java:133)
              at java.io.FilterInputStream.read(FilterInputStream.java:107)
              at java.util.Properties$LineReader.readLine(Properties.java:435)
              at java.util.Properties.load0(Properties.java:353)
              at java.util.Properties.load(Properties.java:341)
              at org.apache.kylin.jdbc.shaded.org.apache.calcite.avatica.DriverVersion.load(DriverVersion.java:104)
              at org.apache.kylin.jdbc.Driver.createDriverVersion(Driver.java:88)
              at org.apache.kylin.jdbc.shaded.org.apache.calcite.avatica.UnregisteredDriver.<init>(UnregisteredDriver.java:56)
              at org.apache.kylin.jdbc.Driver.<init>(Driver.java:70)
      By inspecting the Avatica code, the InputStream was not closed after use. 

      //code from Avatica DriverVersion.load
      final InputStream inStream =           driverClass.getClassLoader().getResourceAsStream(resourceName);
      

      Though it is nonsense to calling DriverVersion.load repeatedly,  but the leak is there.

      The code to reproduce the leak is at https://github.com/leonliao/calcite-avatica-driver-version-test. Follow the README to reproduce the problem.

       

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                xiaoboliao Xiaobo Liao
                Reporter:
                xiaoboliao Xiaobo Liao
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2.5h
                  2.5h