Re: coonection lost after idle time

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sun Mar 30 2003 - 16:03:04 EST

  • Next message: Troy McKinnon: "Fw: Failed to load domain and/or its maps/nodes"

    I was writing an FAQ entry discussing dropped connections for the next
    release of Cayenne. As a part of this I did some research, and was able
    to actually fix this for Oracle [of course the Oracle fix is not a part
    of the official Cayenne distro, but will be included in tomorrow's
    nightly build]. Here is a snip from the upcoming FAQ, since this has
    been discussed at least 3 times on this list:

    Question: When my application is idle for a long period of time, I get
    'connection was lost' or similar errors?

    There can be a few reasons for this error: some database servers will
    automatically drop idle client connections, database server may have
    been restarted, etc. Pooled connections may become invalid over a
    period of time due to one of these reasons, resulting in exceptions
    thrown when such connections are used.

    Cayenne's default connection pool implements a few checks for invalid
    connections, and reconnects if possible. Unfortunately due to driver
    differences, this does not work reliably across database engines (One
    database were reconnects work rather well is Oracle). If you are still
    having this problem, here is a few suggested solutions:

         * If you are using MySQL, MYSQL JDBC driver offers "auto-reconnect"
    feature. Use a URL parameter "autoReconnect" set to "true" to enable
    reconnection. E.g.: jdbc:mysql://localhost/test?autoReconnect=true.
    Unfortunately other databases do not have such feature.
         * Configure your database server to prevent idle connections from
    being automatically closed. Consult your database documentation on the
    details.
         * Use a third party connection pool implementation, that performs
    explicit connection validation, e.g. by running a test query every time
    before checking it out. It can be configured in many different ways,
    e.g. as a DataSource accessible via JNDI.

    Andrus

    On Tuesday, March 18, 2003, at 10:33 AM, Andrus Adamchik wrote:

    > From the posted stack trace, I assume that Halbig is on MySQL. In this
    > case the following advise might apply:
    >
    >
    > http://www.objectstyle.org/cayenne/lists/cayenne-user/2003/01/> 0025.html
    >
    > Andrus
    >
    >
    >> Configuration failure on your side. You need to set the connection
    >> differently depending on which database you are using. What is the
    >> connection URL you are using now?
    >>
    >> -----Original Message-----
    >> From: Halbig Thomas [mailto:thomas.halbi..interthur.ch]
    >> Sent: March 18, 2003 2:43 AM
    >> To: cayenne-use..bjectstyle.org
    >> Subject: coonection lost after idle time
    >>
    >>
    >> Hello,
    >>
    >> I'have a problem with the database connection.
    >> It seems so that cayenne sets the connections back after a specific
    >> idle
    >> time. After them, I try to access to the database I will receive the
    >> following Exception:
    >>
    >> WARN DefaultOperationObserver: global exception
    >> java.sql.SQLException: Communication link failure: java.io.IOException
    >> at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
    >> at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
    >> at com.mysql.jdbc.MysqlIO.sqlQuery(Unknown Source)
    >> at com.mysql.jdbc.Connection.execSQL(Unknown Source)
    >> at com.mysql.jdbc.Connection.execSQL(Unknown Source)
    >> at com.mysql.jdbc.Connection.setAutoCommit(Unknown Source)
    >> at
    >> org.objectstyle.cayenne.conn.PooledConnectionImpl.getConnection(Pooled
    >> Connec
    >> tionImpl.java:121)
    >> at
    >> org.objectstyle.cayenne.conn.PoolManager.getConnection(PoolManager.jav
    >> a:367)
    >> at
    >> org.objectstyle.cayenne.conn.PoolManager.getConnection(PoolManager.jav
    >> a:337)
    >> at
    >> org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:2
    >> 43)
    >> at
    >> org.objectstyle.cayenne.access.DataDomain.performQueries(DataDomain.ja
    >> va:427
    >> )
    >> at
    >> org.objectstyle.cayenne.access.DataContext.performQueries(DataContext.
    >> java:8
    >> 84)
    >> at
    >> org.objectstyle.cayenne.access.DataContext.performQuery(DataContext.ja
    >> va:976
    >> )
    >> at
    >> org.objectstyle.cayenne.access.DataContext.performQuery(DataContext.ja
    >> va:813
    >> )
    >> at
    >> com.winterthur.cm.controller.LocalAccountManager.getAllAccounts(LocalA
    >> ccount
    >> Manager.java:254)
    >> at
    >> com.winterthur.cm.cron.UpdateBalancesWorker.handleAlarm(UpdateBalances
    >> Worker
    >> .java:49)
    >> at
    >> com.jalios.jdring.AlarmManager.notifyListeners(AlarmManager.java:378)
    >> at com.jalios.jdring.AlarmWaiter.run(AlarmWaiter.java:108)
    >>
    >> Any idea, is this is a bug on cayenne side or a configuration failure
    >> on
    >> my side?
    >>
    >> Thanx in advance
    >> Thomas
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Sun Mar 30 2003 - 16:07:33 EST