artemp/trac2github — Issue #295: thread unsafe gdal layer initialization (libgeotiff)
Author: artemp
Created: 2011-10-09 20:25:45+00:00
State: open
Labels: GDAL_Input_Driver

I experienced segmentation faults after adding gdal layer, when using mod_tile with more then one thread.

Stacktraces originate in various places in cpl_csv.c from libgeotiff library, but have same reason.
It apears, libgeotiff uses global table, to store opened csv files and its indexed contents while opening tiff file (reading headers etc.). These csv files (/usr/share/epsg_csv/*.csv) looks like some dictionaries for converting geotiff tags/values to human readible ones.

In effect, these happens:[[BR]]
- closing already closed files[[BR]]
- accessing or releasing already released memory

It only affects (?) initialization step: GTiffDataset::Open in gdaldataset.cpp:1964, when tiff file is examined for all geo tags.
After that step I haven't noticed any thread related problems.

Solution for me is adding synchronization in mod_tile to create new thread only after load_map has finished (or adding enough sleep to have the same effect).

Problem in fact is in external library (but mapnik can be build against internall copy), so it's probably not mapnik bug.