Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-5215

On a document save, the transaction may be left without being either rolled back or committed.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Critical
    • None
    • 2.3
    • Storage
    • Trivial

    Description

      This question: http://xwiki.markmail.org/message/tdht5ecsnjswmqg3 still haven't got a satisfying answer. I'm not a database expert, but I agree with Sergiu that the code is wrong.

      An example of when this occur is when a document with an attachment is moved to the recycle bin, then you use a script to create a new document with the same name and with an attachment with the same file name. The save will fail without rolling back the transaction. (Whether the save should fail or not in this situation is a different question, but clearly, the database should remain consistent.)

      The method endTransaction should look something like this:

          /**
           * Ends a transaction
           * 
           * @param context
           * @param commit should we commit or not
           * @param withTransaction
           */
          protected void endTransaction(XWikiContext context, boolean commit, boolean withTransaction)
          {
              Session session = getSession(context);
              Transaction transaction = getTransaction(context);
              if (transaction != null) {
                  try {
                      setSession(null, context);
                      setTransaction(null, context);
      
                      // We need to clean up our connection map first because the connection will
                      // be aggressively closed by hibernate 3.1 and more
                      preCloseSession(session);
      
                      if (log.isDebugEnabled()) {
                          log.debug("Releasing hibernate transaction " + transaction);
                      }
                      if (commit) {
                          transaction.commit();
                      } else {
                          transaction.rollback();
                      }
                  } catch (Exception e) {
                      try {
                          transaction.rollback();
                      } catch (Exception e) {
                          /*
                           * The rollback failed.  Thus, the database might
                           * be left in an inconsistent state.  So, maybe we
                           * should throw a java.io.IOError here?  I have
                           * not seen any example code on how to deal with
                           * this situation, and I don't see how we can
                           * recover from this situation.
                           */
                      }
                      throw new RuntimeException(e);
                  } finally {
                      closeSession(session);
                  }
              }
          }
      

      Attachments

        Activity

          People

            tmortagne Thomas Mortagne
            aj Andreas Jonsson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: