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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • avatica-1.13.0
    • avatica-1.14.0
    • avatica
    • 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

        1. stream_not_closed.png
          285 kB
          Xiaobo Liao

        Issue Links

          Activity

            People

              xiaoboliao Xiaobo Liao
              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