geo-data / node-mapserv

All the functionality of Mapserver's `mapserv` CGI program made available to Node.js
BSD 2-Clause "Simplified" License
21 stars 8 forks source link

mapserv.Map.FromFile keeps the file open when it includes a non-existent file #13

Closed emilecantin closed 8 years ago

emilecantin commented 10 years ago

There seems to be an issue with the cleanup of resources when there is an error reading an INCLUDEd file.

Here is an example mapfile illustrating the issue:

# Used in the `node-mapserv` wms example
MAP
  NAME "wms-countries"
  # Map image size
  SIZE 400 400
  UNITS meters
  EXTENT -20037508.3392 -20037508.3392 20037508.3392 20037508.3392

  PROJECTION
    'init=epsg:3857'
  END

  IMAGECOLOR 255 255 255

  #CONFIG MS_ERRORFILE "mapserv-error.log"
  #DEBUG 5

  WEB
    # WMS server settings
    METADATA
      'ows_title'           'wms-countries'
      'ows_onlineresource'  ''
      'ows_srs'             'EPSG:3857'
      'ows_enable_request'  '*'
    END
  END

  LAYER
    NAME "countries"
    TYPE POLYGON
    STATUS ON   
    INCLUDE './DATASOURCE.map'
    DATA "the_geom from (
            select c.worcntry_i as gid, 
            name,
            continent,
            ST_SimplifyPreserveTopology(c.the_geom_900913, 5000) as the_geom
            from data.%countTable% as c
        ) as subquery using unique gid using srid=900913"
    PROJECTION
      'init=epsg:3857'
    END
    DUMP TRUE
    TEMPLATE "foo"
    TOLERANCE 5
    METADATA
      "ows_title"           "Countries (WMS)"
      "ows_srs"             "EPSG:3857"
      "ows_name"            "countries"
      "ows_server_version"  "1.0.0"
      "ows_format"          "image/png"
      "gml_featureid"       "gid"
      "gml_include_items"   "all"
    END
    CLASSITEM "continent"

    VALIDATION
      # if the countTable parameter is present in the query string,
      # then its value is used as the table name
      'countTable' '^countries|vw_countries_extent$'
      'default_countTable' 'countries'
    END

    CLASS
      NAME "Africa"
      EXPRESSION "Africa"
      STYLE
        COLOR '#fed52e'
        OUTLINECOLOR '#666666'
        OUTLINEWIDTH 0.3
      END
    END
    CLASS
      NAME "Antarctica"
      EXPRESSION "Antarctica"
      STYLE
        COLOR '#0040ff'
        OUTLINECOLOR '#666666'
        OUTLINEWIDTH 0.3
      END
    END
    CLASS
      NAME "Asia"
      EXPRESSION "Asia"
      STYLE
        COLOR '#f33e01'
        OUTLINECOLOR '#666666'
        OUTLINEWIDTH 0.3
      END
    END
    CLASS
      NAME "Oceania"
      EXPRESSION "Australia"
      STYLE
        COLOR '#c04080'
        OUTLINECOLOR '#444444'
        OUTLINEWIDTH 0.3
      END
    END
    CLASS
      NAME "Europe"
      EXPRESSION "Europe"
      STYLE
        COLOR '#c10000'
        OUTLINECOLOR '#333333'
        OUTLINEWIDTH 0.3
      END
    END
    CLASS
      NAME "North America"
      EXPRESSION "North America"
      STYLE
        COLOR '#00cc00'
        OUTLINECOLOR '#666666'
        OUTLINEWIDTH 0.3
      END
    END
    CLASS
      NAME "South America"
      EXPRESSION "South America"
      STYLE
        COLOR '#008000'
        OUTLINECOLOR '#222222'
        OUTLINEWIDTH 0.3
      END
    END
  END
END

The INCLUDE './DATASOURCE.map' file defines some PostGIS connections.

When calling mapserv.Map.FromFile on this file, the file stays open.

homme commented 10 years ago

Hi,

Can you give me the base mapserver version and node-mapserv version you're using as well as post a minimal script replicating the problem? I tried the mapfile you posted with the example/wms-server.js script: the script died with the error MapserverError: Could not load mapfile. You say...

When calling mapserv.Map.FromFile on this file, the file stays open.

Do you mean there is an open filehandle to the mapfile when you handle the error and keep the node process running?

Thanks.

homme commented 10 years ago

I've replicated the problem and it turns out it's an upstream issue with the core mapserver code: I have filed an issue about it at mapserver/mapserver#4871.

emilecantin commented 10 years ago

Cool, thanks!

homme commented 10 years ago

It doesn't fix your issue but i've released a version 0.1.5 (available on npm) that improves the error handling in the above situation to mimic the output created by core mapserver (e.g. the shp2img program).

emilecantin commented 8 years ago

The referenced issue was closed, so I'm closing this. Thanks!