core icon indicating copy to clipboard operation
core copied to clipboard

Race condition when importing content

Open dsilvam opened this issue 11 years ago • 2 comments

Reproduced in 3.3

When you import content there is a race condition which can provoke a NullPointerException. Although the issue occurs randomly, it seems to happen more frequently when checking the keys to import in the UI.

Steps to reproduce:

  1. Put together a CSV file with one row of an existing piece of content of type 'Location' (could be any, but content types with lots of fields help to reproduce), updating some of its values
  2. Go to the 'Content' Tab and select the type 'Location'.
  3. Click 'Import Content' at the right upper corner dropdown
  4. Check all the 'Key Fields', choose the CSV and click 'Go To Preview'
  5. Click 'Import Content' in the 'View Conflicts' window.
  6. If you get the result message saying that 1 record was updated, repeat again from step 4. If you instead just get a "Success" message, you would have reproduced the issue

Error in log:

org.postgresql.util.PSQLException: Cannot rollback when autoCommit is enabled.
Exception in thread "Thread-58" java.lang.NullPointerException
    at org.apache.catalina.connector.Request.setAttribute(Request.java:1509)
    at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:503)
    at javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:284)
    at com.liferay.portlet.RenderRequestImpl.setAttribute(RenderRequestImpl.java:405)
    at com.dotmarketing.portal.struts.DotPortletAction._handleException(DotPortletAction.java:703)
    at com.dotmarketing.portlets.contentlet.action.ImportContentletsAction.access$200(ImportContentletsAction.java:49)
    at com.dotmarketing.portlets.contentlet.action.ImportContentletsAction$1.run(ImportContentletsAction.java:250)

The cause of the error is 'httpReq.getSession()' returns null in this line https://github.com/dotCMS/core/blob/master-3.3/src/com/dotmarketing/portlets/contentlet/action/ImportContentletsAction.java#L211 which makes 'httpReq.getSession().getAttribute("filetoimport")' to throw a NPE

This occurs when the Struts Action returns before the importer thread executes session.getAttribute

A workaround is to include a Thread.sleep(someMilisecs) in this line https://github.com/dotCMS/core/blob/master-3.3/src/com/dotmarketing/portlets/contentlet/action/ImportContentletsAction.java#L279 to make the importerThread win the race

dsilvam avatar Sep 17 '15 18:09 dsilvam

The NPE within the processing thread still occurs in dotCMS 4.2.1. The proposed workaround (sleeping the main thread after starting the processing of the import) does allow us to perform an import.

hmboonstra avatar Dec 20 '17 09:12 hmboonstra

This issue has been automatically marked as stale because it has not had activity within the past 90 days. It will be closed in 30 days no further activity occurs. Thank you.

stale[bot] avatar Sep 28 '19 09:09 stale[bot]