Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-200

Connection Pool does not handle stale (closed) connections

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0 Beta 2
    • Fix Version/s: 1.0.0
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Operating System: other
      Platform: Sun
    • Bugzilla Id:
      1879

      Description

      Struts connection pool implemented in GenericDataSource.java does not handle
      stale connections.
      Stale connections are connections having been closed by the database. This
      could be due to no activity timeout (such as wait_timeout in mysql) or the
      database was down and up again. Currently when returning a pool connection to
      a caller in getConnection(), Struts does not check if the real database
      connection of that pool connection has been closed or not.

      Below is my patch for this problem in the GenericDataSource.java, revision 1.5

          • GenericDataSource.java.r1.5 Wed May 23 17:44:12 2001
          • GenericDataSource.java.r1.5fixed Wed May 23 17:31:07 2001
            ***************
          • 402,414 ****

      // Return an existing connection from the pool if there is one
      synchronized (connections) {
      ! if (!connections.isEmpty())

      { ! useCount++; GenericConnection connection = (GenericConnection) connections.removeFirst(); // unclose the connection's wrapper connection.setClosed(false); return(connection); ! // return ((Connection) connections.removeFirst()); DEBUG }

      }

      — 402,425 ----

      // Return an existing connection from the pool if there is one
      synchronized (connections) {
      ! while (!connections.isEmpty()) {
      GenericConnection connection = (GenericConnection)
      connections.removeFirst();
      + // Checking for stale connection. Stale connections are
      connections
      + // closed by the database. This could be due to no
      activity
      + // timeout (such as mysql wait_timeout) or the database
      was down
      + // and up again.
      + if (connection.getConnection().isClosed())
      +

      { + activeCount --; + connection = null; + continue; + }

      + else

      { // unclose the connection's wrapper + useCount++; connection.setClosed(false); return(connection); ! }

      }
      }

        Attachments

          Activity

            People

            • Assignee:
              craigmcc Craig R. McClanahan
              Reporter:
              hnguyen@solers.com hnguyen
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: