Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-32523

Fix concurrent update issue in SQL Server when updating documents' ACLs simultaneously

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2021.0, 2023.0
    • Fix Version/s: None
    • Component/s: Core

      Description

      When an event handler, triggered by documentCreated event, updates the document's ACLs, and is executed several times almost simultaneously, the following error occurs:

      2024-05-10T11:56:43,626 ERROR [http-nio-0.0.0.0-8080-exec-8] [org.nuxeo.ecm.automation.core.events.OperationEventListener] Failed to handle event documentCreated using chain: javascript.SetACE
      org.nuxeo.ecm.core.api.ConcurrentUpdateException: Failed to save session, Concurrent update
      	at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCConnection.checkConcurrentUpdate(JDBCConnection.java:172) ~[nuxeo-core-storage-sql-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper.updateReadAcls(JDBCMapper.java:904) ~[nuxeo-core-storage-sql-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.storage.sql.SoftRefCachingMapper.updateReadAcls(SoftRefCachingMapper.java:122) ~[nuxeo-core-storage-sql-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.storage.sql.SessionImpl.updateReadAcls(SessionImpl.java:1185) ~[nuxeo-core-storage-sql-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.storage.sql.SessionImpl.flush(SessionImpl.java:251) ~[nuxeo-core-storage-sql-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.storage.sql.SessionImpl.save(SessionImpl.java:229) ~[nuxeo-core-storage-sql-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.storage.sql.coremodel.SQLSession.save(SQLSession.java:132) ~[nuxeo-core-storage-sql-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.api.AbstractSession.save(AbstractSession.java:1697) ~[nuxeo-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.automation.LoginStack$Entry.dispose(LoginStack.java:131) ~[nuxeo-automation-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.automation.LoginStack.clear(LoginStack.java:104) ~[nuxeo-automation-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.automation.OperationContext.close(OperationContext.java:213) ~[nuxeo-automation-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.automation.core.events.EventHandlerRegistry.handleEvent(EventHandlerRegistry.java:132) [nuxeo-automation-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.automation.core.events.OperationEventListener.handleEvent(OperationEventListener.java:40) [nuxeo-automation-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.event.impl.EventServiceImpl.fireEvent(EventServiceImpl.java:280) [nuxeo-core-event-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.api.AbstractSession.notifyEvent(AbstractSession.java:318) [nuxeo-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.core.api.AbstractSession.createDocument(AbstractSession.java:820) [nuxeo-core-2021.53.3.jar:?]
      	at org.nuxeo.ecm.restapi.server.jaxrs.JSONDocumentObject.doPost(JSONDocumentObject.java:100) [nuxeo-rest-api-server-2021.53.3.jar:?]
      

      A customer reports that just creating 2 documents in parallel triggers the error.

      The following basic event handler executed on event documentCreated triggers the error:

      function run(input, params) {
        Console.warn('<SetACE> ' + input.path);
        input = Auth.LoginAs(input, { 'name': 'Administrator'} );
        Console.warn('<SetACE> Updating ACE ' + input.path);
        input = Document.AddACE(input, { 'permission': 'ReadWrite','user': 'Administrator'} );
        Console.warn('<SetACE> Done ');
        return input;
      }
      

      How to reproduce:

      • set up a LTS 2021 Nuxeo instance configured to use MS SQL Server for the document repository
      • install the attached Marketplace package mssql-concurrency-issue-1.0.0.zip containing the event handler triggering the issue
      • start the Nuxeo Platform
      • execute the attached script parallel_create_documents.sh that creates 5 File documents in parallel

      Expected result: 5 File documents are created in /default-domain/UserWorkspaces/Administrator
      Actual result: not all 5 File documents are created in /default-domain/UserWorkspaces/Administrator and Concurrent update errors are reported in server.log (see attached log file server.log )

      A workaround is to set the event handler asynchronous.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: