db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Boehle" <jboe...@gmail.com>
Subject Re: question about shutdown
Date Tue, 19 Sep 2006 17:58:25 GMT
On 9/19/06, Stanley Bradbury <Stan.Bradbury@gmail.com> wrote:
> Jason Boehle wrote:
> > I am using Derby embedded in an application.  If the database is
> > shutdown via opening a connection to
> > jdbc:derby:/path/to/db;shutdown=true, what should happen to existing
> > open connections to that database?
> >
> Any existing connections to that DB will be closed.  Any attempts to use
> such a connection will result in an exception.

I wrote a small test that exercised this, and Derby leaks memory like
crazy (almost 1MB per database) if this happens.  Here is the code for
my test:

public class TestDerbyBug {
    public static void main(String[] args) {
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            while (true) {
                final String dir =
System.getProperty("java.io.tmpdir") + java.io.File.separator +
"TestDerbyBug-" + Math.abs(new java.util.Random().nextInt());
                final String url = "jdbc:derby:" + dir;
                java.sql.Connection conn =
java.sql.DriverManager.getConnection(url + ";create=true");
                // oops, forgot to close conn before shutting down...
                try {
                    java.sql.DriverManager.getConnection(url +
";shutdown=true");
                    assert false; // shouldn't get here
                }
                catch (java.sql.SQLException e) {
                    // ignore, shutdown is supposed to throw
                }
                // finally got around to remembering to close conn
                conn.close();
            }
        }
        catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

If you run that class with a max heap of 16MB (-Xmx16m), it will only
be able to create about 18-20 databases before running out of memory.
If you move the 'conn.close()' line above the inner try statement, no
memory is leaked and it can run for at least 15 minutes (I got bored
and killed it at that point).  I tried this with 10.1.2.1, 10.1.3.1,
and 10.2.1.3-beta and got the same results on all releases.  I am
running it under JRE 1.5.0_08.

There is a similar bug reported, DERBY-23, that is reported fixed in
10.2, if that helps at all.

Obviously, the easiest fix is to make sure to clean up my connections
before shutting down.  :)

Mime
View raw message