question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash when importing fiona after using sqlite3_modspatialite_init

See original GitHub issue

Expected behavior and actual behavior.

On import of fiona in a particular script I get a crash:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

edit: (when building the PROJ library in the fiona wheel with debug flags, this turns into a segfault)

In my script I first load data through sqlalchemy and then output it through fiona. For this I need to enable spatialite extensions inside the sqlite3 driver, and this is where the cause of the error is. The issue only happens when importing fiona after loading the spatalite extension.

When I compile Fiona myself (against system GDAL 3.4.1) the issue vanishes.

Using GDB I can trace the crash back to the import of fiona.ogrext. This stack trace leads via the vendored PROJ to the system’s PROJ. (edited stack trace 9th Nov)

libproj.so.22!std::__shared_ptr<osgeo::proj::metadata::GeographicExtent, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<osgeo::proj::metadata::GeographicExtent, (__gnu_cxx::_Lock_policy)2> * const this) (/usr/include/c++/11/bits/shared_ptr_base.h:1153)
libproj.so.22!std::shared_ptr<osgeo::proj::metadata::GeographicExtent>::operator=(std::shared_ptr<osgeo::proj::metadata::GeographicExtent> * const this) (/usr/include/c++/11/bits/shared_ptr.h:359)
libproj.so.22!dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> >::operator=(dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> > * const this) (/home/casper/code/proj/include/proj/nn.hpp:89)
libproj.so.22!std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m<dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> > const*, dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> >*>(const dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> > * __first, const dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> > * __last, dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> > * __result) (/usr/include/c++/11/bits/stl_algobase.h:385)
libproj-1ae2ebf9.so.22.2.1![Unknown/Just-In-Time compiled code] (Unknown Source:0)
libproj-1ae2ebf9.so.22.2.1!osgeo::proj::metadata::Extent::create(osgeo::proj::util::optional<std::string> const&, std::vector<dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> >, std::allocator<dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::GeographicExtent> > > > const&, std::vector<dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::VerticalExtent> >, std::allocator<dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::VerticalExtent> > > > const&, std::vector<dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::TemporalExtent> >, std::allocator<dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::TemporalExtent> > > > const&) (Unknown Source:0)
libproj-1ae2ebf9.so.22.2.1!osgeo::proj::metadata::Extent::createFromBBOX(double, double, double, double, osgeo::proj::util::optional<std::string> const&) (Unknown Source:0)
libproj-1ae2ebf9.so.22.2.1![Unknown/Just-In-Time compiled code] (Unknown Source:0)
ld-linux-x86-64.so.2!call_init(struct link_map * l, int argc, char ** argv, char ** env) (dl-init.c:70)
(...)

Steps to reproduce the problem.

Preparation:

$ sudo apt install libsqlite3-mod-spatialite
$ pip install fiona

Actual script:

import sqlite3

con = sqlite3.connect("")
con.enable_load_extension(True)
con.execute("select load_extension('mod_spatialite', 'sqlite3_modspatialite_init')")

import fiona

Operating system

Ubuntu 22.04 LTS, with system python 3.10.6

Fiona and GDAL version and provenance

Used the wheel: Fiona-1.8.22-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Which has PROJ 8.2.1. My system PROJ is also 8.2.1.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rouaultcommented, Nov 14, 2022

in case you have seen this before or have an idea this could be an issue in PROJ or in our packaging

Well, may I say that pip packages embedding binaries is a broken concept by itself, especially on Linux where the dynamic loader doesn’t try to be “consistant” in such situation, and that this issue just shows it 😃 That said, to be more constructive, the issue could probably be worked around by building both PROJ and GDAL of the Fiona wheel with -DPROJ_RENAME_SYMBOLS -DPROJ_INTERNAL_CPP_NAMESPACE in CFLAGS and CXXFLAGS whose effect is to prefix PROJ C symbols with internal_ and change its C++ namespace to osgeo::internalproj Note: the above scenario would likely break when mixing mod_spatialite from the system and pyproj from pip as it can’t use that renaming trick

0reactions
elfjescommented, Nov 14, 2022

As a workaround, I found that import order does make a difference. So make sure to import fiona or pyogrio before loading mod_spatialite and you should be fine. mod_spatialite either always uses the os version of PROJ or it is fine with fiona’s version, not sure which one it uses.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jupyter kernel dies when importing fiona before geopandas
I think I installed both of them using pip. Fiona 1.8.13 geopandas 0.6.2. It crashes on read_file. Error: python3(16790,0x105419dc0) malloc: *** ...
Read more >
Fiona write crashes - python
I am trying to write a new shapefile with fiona but after creating the features, i keep getting this output after the program...
Read more >
import geopandas successfully, but raise issue with fiona ...
I am Windows and using python through jupyternotebook. python 3.9.7, ... Importing fiona resulted in: DLL load failed while importing ogrext.
Read more >
Xcode crash when importing Collada file
I am using Xcode 8 (beta) and 10.12 (beta). It happens with any .dae file, for example hero.dae from WWDC SceneKit slides. Actually,...
Read more >
main@fiona.groups.io | Topics
Hello (First message on groups.io here: I hope I'm following locale rules, if not, ... When we import fiona (1.8.21) into our python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found