Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-14510

Fix upgrade tasks that access the database through a connection from the HibernateSession which is later garbage collected

    XMLWordPrintable

Details

    Description

      There is a repeated pattern in upgrade tasks to get a Datasource like this -

      private DataSource getDataSource()
      {
          Session hibernateSession = SessionFactoryUtils.getSession(sessionFactory, true);
          Connection conn;
          try
          {
              conn = hibernateSession.connection();
          }
          catch (HibernateException e)
          {
               throw new RuntimeException(e);
          }
          return new SingleConnectionDataSource(conn, true);
      }
      

      However this has a bug that could cause database connectivity to be lost during the upgrade.

      You return from the method a datasource containing a connection returned from a Hibernate session and then continue to use this datasource during the upgrade operations. However, the Hibernate session has since gone out of scope and at some point soon as the SessionImpl is garbage collected and finalized the connection within your datasource is going to be closed.

      This affects the following in Confluence -

      ConvertAdministerConfluenceToSystemAdministratorUpgradeTask
      CorrectAttachmentCreatorUpgradeTask
      PersonalInformationRepairTask
      OSUEntityMigrator

      It's just a matter of timing that determines whether these upgrade tasks will be successful or not

      Attachments

        Activity

          People

            pcurren Paul Curren
            pcurren Paul Curren
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: