spine-tools / Spine-Toolbox

Spine Toolbox is an open source Python package to manage data, scenarios and workflows for modelling and simulation. You can have your local workflow, but work as a team through version control and SQL databases.
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
73 stars 18 forks source link

Program crashes with segmentation fault in importer specification editor #2121

Closed sjvrijn closed 10 months ago

sjvrijn commented 1 year ago

As I was testing my implementation for #2046, I frequently encountered segmentation faults. I'm working on Windows with Python 3.10.11. These segfaults occur both when starting the program from the 'git bash' terminal, as well as when starting from within PyCharm. If anything, starting from PyCharm seems to make it easier to segfault.

The following steps have frequently (but not always) led to a crash:

  1. Open spinetoolbox
  2. In a new project, create an importer
  3. Open the importre specification editor, selecting any connector
  4. Create one or two source table entries (e.g. 'a' and 'b')
  5. Switch back and forth between different source table entries a few times
  6. Remove all mappings from source table entry 'a'
  7. Shortly after, 'spam-click' the 'Add' button to add new mappings.
  8. Program hangs for a moment and crashes, reporting only a segmentation fault (besides the IndexError reported in #2119 )
$ spinetoolbox
TypeError: print_exception(): Exception expected for value, str found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Sander\src\Spine-Toolbox\src\spine-items\spine_items\importer\widgets\import_mappings.py", line 171, in _change_flattened_mappings
    if not current.isValid():
  File "C:\Users\Sander\src\Spine-Toolbox\src\spine-items\spine_items\importer\mvcmodels\mappings_model.py", line 410, in parent
    index_item = index.internalPointer()
  File "C:\Users\Sander\src\Spine-Toolbox\src\spine-items\spine_items\importer\mvcmodels\mappings_model.py", line 410, in parent
    index_item = index.internalPointer()
  File "C:\Users\Sander\src\Spine-Toolbox\src\spine-items\spine_items\importer\mvcmodels\mappings_model.py", line 410, in parent
    index_item = index.internalPointer()
  [Previous line repeated 1 more time]
  File "C:\Users\Sander\src\Spine-Toolbox\src\spine-items\spine_items\importer\mvcmodels\mappings_model.py", line 372, in index
    return self.createIndex(row, 0, parent_item.mapping_list[row])
IndexError: list index out of range                                                     # <-- This error triggers on selecting '<rename this to add table>' to create 'b'
QAbstractItemView::closeEditor called with an editor that does not belong to this view  # <-- This triggered on naming 'b'
Segmentation fault                                                                      # <-- Only output when the program crashes

Installed package version details:

``` $ python --version Python 3.10.11 $ pip freeze alabaster==0.7.13 alembic==1.10.4 appdirs==1.4.4 aspy.yaml==1.3.0 astroid==2.15.4 asttokens==2.2.1 attrs==23.1.0 Babel==2.12.1 backcall==0.2.0 black==23.3.0 bleach==6.0.0 boto3==1.26.124 botocore==1.29.124 cached-property==1.5.2 certifi==2022.12.7 cfgv==3.3.1 chardet==5.1.0 charset-normalizer==3.1.0 click==8.1.3 colorama==0.4.6 coloredlogs==14.0 comm==0.1.3 commonmark==0.9.1 contourpy==1.0.7 croniter==1.3.14 cycler==0.11.0 dagster==0.12.8 datapackage==1.15.2 debugpy==1.6.7 decorator==5.1.1 dill==0.3.6 distlib==0.3.6 docstring-parser==0.15 docutils==0.16 et-xmlfile==1.1.0 exceptiongroup==1.1.1 executing==1.2.0 Faker==18.6.0 filelock==3.12.0 fire==0.5.0 fonttools==4.39.3 GDX2py==2.1.1 gdxcc==8.33.2.post1 grpcio==1.54.0 grpcio-health-checking==1.48.2 humanfriendly==10.0 identify==2.5.23 idna==3.4 ijson==3.2.0.post0 imagesize==1.4.1 importlib-metadata==6.6.0 iniconfig==2.0.0 ipykernel==6.22.0 ipython==8.13.1 ipython-genutils==0.2.0 isodate==0.6.1 isort==5.12.0 jaraco.classes==3.2.3 jedi==0.18.2 jill==0.11.3 Jinja2==2.11.3 jmespath==1.0.1 jsonlines==3.1.0 jsonpointer==2.3 jsonschema==4.17.3 jupyter-client==6.1.12 jupyter_core==5.3.0 keyring==23.13.1 kiwisolver==1.4.4 lazy-object-proxy==1.9.0 linear-tsv==1.1.0 Mako==1.2.4 markdown-it-py==2.2.0 MarkupSafe==2.0.1 matplotlib==3.7.1 matplotlib-inline==0.1.6 mccabe==0.7.0 mdurl==0.1.2 more-itertools==9.1.0 mypy-extensions==1.0.0 nest-asyncio==1.5.6 networkx==3.1 nodeenv==1.7.0 numpy==1.24.3 openpyxl==3.1.2 packaging==23.1 pandas==2.0.1 parso==0.8.3 pathspec==0.11.1 pendulum==2.1.2 pickleshare==0.7.5 Pillow==9.5.0 pkginfo==1.9.6 platformdirs==3.5.0 pluggy==1.0.0 pre-commit==3.3.1 prompt-toolkit==3.0.38 protobuf==3.20.3 psutil==5.9.1 pure-eval==0.2.2 Pygments==2.15.1 pylint==2.17.4 PyMySQL==1.0.3 pyodbc==4.0.39 pyparsing==3.0.9 pyreadline3==3.4.1 pyrsistent==0.19.3 PySide6==6.4.3 PySide6-Addons==6.4.3 PySide6-Essentials==6.4.3 pytest==7.3.1 python-dateutil==2.8.2 python-gnupg==0.5.0 pytz==2023.3 pytzdata==2020.1 pywin32==306 pywin32-ctypes==0.2.0 PyYAML==6.0 pyzmq==25.0.2 qtconsole==5.4.2 QtPy==2.3.1 readme-renderer==37.3 recommonmark==0.7.1 requests==2.29.0 requests-futures==1.0.0 requests-toolbelt==1.0.0 rfc3986==2.0.0 rich==13.3.5 Rx==1.6.3 s3transfer==0.6.0 scipy==1.10.1 semantic-version==2.10.0 shiboken6==6.4.3 six==1.16.0 snowballstemmer==2.2.0 Sphinx==5.1.1 sphinx-autoapi==2.0.1 sphinx-rtd-theme==1.2.0 sphinxcontrib-applehelp==1.0.4 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.1 sphinxcontrib-jquery==4.1 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 -e git+https://github.com/spine-tools/spine-engine.git@7be63302466f2826ab80ffa0730e31a052770fc4#egg=spine_engine -e git+https://github.com/spine-tools/spine-items.git@1182384bea156f9687c480d83fb04bdf814860bc#egg=spine_items -e git+https://github.com/spine-tools/Spine-Database-API.git@0e6c67b17b5785671330fd84783363b2c99254ae#egg=spinedb_api -e git+ssh://git@github.com/spine-tools/Spine-Toolbox.git@3f57b95937865d5fef9cdb01c937f0a0850839e4#egg=spinetoolbox SQLAlchemy==1.3.24 stack-data==0.6.2 tableschema==1.20.2 tabulate==0.9.0 tabulator==1.53.5 termcolor==2.3.0 toml==0.10.2 tomli==2.0.1 tomlkit==0.11.8 toposort==1.10 tornado==6.3.1 tqdm==4.65.0 traitlets==5.9.0 twine==4.0.2 typing-compat==0.1.0 typing_extensions==4.5.0 tzdata==2023.3 unicodecsv==0.14.1 Unidecode==1.3.6 urllib3==1.26.15 virtualenv==20.23.0 watchdog==3.0.0 wcwidth==0.2.6 webencodings==0.5.1 wget==3.2 wrapt==1.15.0 xlrd==2.0.1 zipp==3.15.0 ```
soininen commented 1 year ago

Are you using Anaconda? If so, see this section in README.md.

ptsavol commented 1 year ago

We do have a segmentation fault lurking somewhere. It appears randomly when our github action runs the unit tests. I haven't been able to reproduce it so I hope this is it. Good luck @sjvrijn!

sjvrijn commented 1 year ago

I'm not using Anaconda, just regular Python.

jkiviluo commented 1 year ago

@sjvrijn Can this be closed?