Home > Software engineering >  Pytest GDAL: cannot allocate memory in static TLS block
Pytest GDAL: cannot allocate memory in static TLS block

Time:03-19

Here's my GitHub Actions workflow:

name: Test and merge
on:
  push:
    branches:
      - dev
jobs:
  build-test-push:
    services:
      postgres:
        image: postgis/postgis:latest
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: mypass
          POSTGRES_DB: my_test
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
    runs-on: ubuntu-latest
    env:
      POSTGRES_HOST: 172.17.0.1
    steps:
      - name: Checkout
        uses: actions/checkout@master
      - uses: actions/setup-python@v2
        with:
          python-version: '3.10'
      - name: Install dependencies
        run: sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update && sudo apt-get install gdal-bin && pip install -r requirements.txt
      - name: Test
        run: pytest

On the pytest stage the following error is occurring:

Run pytest
  pytest
  shell: /usr/bin/bash -e {0}
  env:
    POSTGRES_HOST: 172.17.0.1
    pythonLocation: /opt/hostedtoolcache/Python/3.10.2/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.2/x64/lib
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.2/x64/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 145, in main
    config = _prepareconfig(args, plugins)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 324, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/_pytest/helpconfig.py", line 102, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1020, in pytest_cmdline_parse
    self.parse(args)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1308, in parse
    self._preparse(args, addopts=addopts)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1210, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pytest_django/plugin.py", line 349, in pytest_load_initial_conftests
    _setup_django()
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/pytest_django/plugin.py", line 235, in _setup_django
    django.setup()
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/apps/config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
    class AbstractBaseUser(models.Model):
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/models/base.py", line 122, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/models/base.py", line 326, in add_to_class
    value.contribute_to_class(cls, name)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/models/options.py", line 207, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/utils/connection.py", line 15, in __getattr__
    return getattr(self._connections[self._alias], item)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
    from .features import DatabaseFeatures
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
    from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
    from django.contrib.gis.db import models
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
    import django.contrib.gis.db.models.functions  # NOQA
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
    from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
    from django.contrib.gis import forms, gdal
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
    from django.contrib.gis.gdal import GDALException
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
    from django.contrib.gis.gdal.datasource import DataSource
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/gdal/datasource.py", line 40, in <module>
    from django.contrib.gis.gdal.driver import Driver
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
    from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
    from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/contrib/gis/gdal/libgdal.py", line 53, in <module>
    lgdal = CDLL(lib_path)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /lib/x86_64-linux-gnu/libstdc  .so.6: cannot allocate memory in static TLS block

Everything worked fine a few commits ago and the GA config didn't change before the crash.

CodePudding user response:

Solved by adding the following line to the workflow:

export LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc  .so.6:$LD_PRELOAD

Source

  • Related