Uploaded image for project: 'GeoServer'
  1. GEOS-7676

Importer doesn't pass spring request context to jobs threads

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.8.6, 2.9.2, 2.10-beta
    • Component/s: Importer
    • Labels:
      None

      Description

      This error happens with geofence-server installed (but is not specific to geofence) and can be reproduced performing the following steps:

      1 - Create an importer task:

      {
         "import": {
            "targetWorkspace": {
               "workspace": {
                  "name": "it.geosolutions"
               }
            }
         }
      }
      
      curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @import.json "http://localhost:8080/geoserver/rest/imports"
      

      2 - Upload the data (I zipped nyc shapefiles provided with GeoServer):

      curl -u admin:geoserver -F name=nyc.zip -F filedata=@nyc.zip "http://localhost:8080/geoserver/rest/imports/0/tasks"
      

      3 - Start the import task asynchronously:

      curl -u admin:geoserver -XPOST "http://localhost:8080/geoserver/rest/imports/0?async=true"
      

      We should get this exception:

      java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
          at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
          at org.geoserver.geofence.GeofenceAccessManager.retrieveCallerIpAddress(GeofenceAccessManager.java:253)
          at org.geoserver.geofence.GeofenceAccessManager.getAccessLimits(GeofenceAccessManager.java:367)
          at it.geosolutions.security.alb.AlbMultiplexingAccessManager.getAccessLimits(AlbMultiplexingAccessManager.java:122)
          at org.geoserver.security.ResourceAccessManagerWrapper.getAccessLimits(ResourceAccessManagerWrapper.java:210)
          at org.geoserver.security.CatalogFilterAccessManager.getAccessLimits(CatalogFilterAccessManager.java:64)
          at org.geoserver.security.SecureCatalogImpl.buildWrapperPolicy(SecureCatalogImpl.java:811)
          at org.geoserver.security.SecureCatalogImpl.buildWrapperPolicy(SecureCatalogImpl.java:771)
          at org.geoserver.security.SecureCatalogImpl.checkAccess(SecureCatalogImpl.java:510)
          at org.geoserver.security.SecureCatalogImpl.getResourceByName(SecureCatalogImpl.java:390)
          at org.geoserver.catalog.impl.AbstractFilteredCatalog.getResourceByName(AbstractFilteredCatalog.java:304)
          at org.geoserver.catalog.impl.AbstractCatalogDecorator.getResourceByName(AbstractCatalogDecorator.java:234)
          at org.geoserver.importer.Importer.findUniqueResourceName(Importer.java:1427)
          at org.geoserver.importer.Importer.addToCatalog(Importer.java:1374)
          at org.geoserver.importer.Importer.doIndirectImport(Importer.java:1000)
          at org.geoserver.importer.Importer.run(Importer.java:852)
          at org.geoserver.importer.Importer.run(Importer.java:802)
          at org.geoserver.importer.Importer$5.call(Importer.java:881)
          at org.geoserver.importer.Importer$5.call(Importer.java:875)
          at org.geoserver.importer.job.Job.call(Job.java:16)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          at java.lang.Thread.run(Thread.java:745)
      

      This error happens because the importer is not sharing the current request context when running a job asynchronously:

      https://github.com/geoserver/geoserver/blob/master/src/extension/importer/core/src/main/java/org/geoserver/importer/Importer.java#L874-L890

        Attachments

          Activity

            People

            • Assignee:
              nmco Nuno Oliveira
              Reporter:
              nmco Nuno Oliveira
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: