Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on adding TopoGeometry column #21807

Closed
qgib opened this issue Nov 6, 2015 · 14 comments
Closed

Segfault on adding TopoGeometry column #21807

qgib opened this issue Nov 6, 2015 · 14 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption High Priority

Comments

@qgib
Copy link
Contributor

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)
Original Redmine Issue: 13781
Affected QGIS version: 2.8.3

Assignee: Sandro Santilli


I'm not sure exactly what triggered this, anyway, here's a backtrace:

(gdb) bt
#_0  0x00007f6eef97b8c8 in QgsPostgresConn::PQstatus (this=0x0) at /usr/src/qgis/qgis-2.8/src/providers/postgres/qgspostgresconn.cpp:1050
#_1  0x00007f6eef9798c1 in QgsPostgresConn::PQexec (this=0x0, query=..., logError=true)
    at /usr/src/qgis/qgis-2.8/src/providers/postgres/qgspostgresconn.cpp:869
#_2  0x00007f6eef95ae94 in QgsPostgresProvider::extent (this=0x6b9f570)
    at /usr/src/qgis/qgis-2.8/src/providers/postgres/qgspostgresprovider.cpp:2467
#_3  0x00007f6f76082669 in QgsVectorLayer::extent (this=0x581fc00) at /usr/src/qgis/qgis-2.8/src/core/qgsvectorlayer.cpp:823
#_4  0x00007f6f75fa2b66 in QgsMapRenderer::updateFullExtent (this=0x2d95be0) at /usr/src/qgis/qgis-2.8/src/core/qgsmaprenderer.cpp:950
#_5  0x00007f6f75fa3356 in QgsMapRenderer::setLayerSet (this=0x2d95be0, layers=...) at /usr/src/qgis/qgis-2.8/src/core/qgsmaprenderer.cpp:1006
#_6  0x00007f6f75667350 in QgsMapCanvasRendererSync::onLayersC2R (this=0x2958b00) at /usr/src/qgis/qgis-2.8/src/gui/qgsmapcanvas.cpp:179
#_7  0x00007f6f756fb1c3 in QgsMapCanvasRendererSync::qt_static_metacall (_o=0x2958b00, _c=QMetaObject::InvokeMetaMethod, _id=10, _a=0x7fffec18b200)
    at /usr/src/qgis/build/2.8/src/gui/moc_qgsmapcanvas.cxx:400
#_8  0x00007f6f74a0687a in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#_9  0x00007f6f756fad8f in QgsMapCanvas::layersChanged (this=0x2d7de20) at /usr/src/qgis/build/2.8/src/gui/moc_qgsmapcanvas.cxx:269
#_10 0x00007f6f75668485 in QgsMapCanvas::setLayerSet (this=0x2d7de20, layers=...) at /usr/src/qgis/qgis-2.8/src/gui/qgsmapcanvas.cpp:448
#_11 0x00007f6f755bc5aa in QgsLayerTreeMapCanvasBridge::setCanvasLayers (this=0x2ec5f80)
    at /usr/src/qgis/qgis-2.8/src/gui/layertree/qgslayertreemapcanvasbridge.cpp:158
#_12 0x00007f6f7571470d in QgsLayerTreeMapCanvasBridge::qt_static_metacall (_o=0x2ec5f80, _c=QMetaObject::InvokeMetaMethod, _id=4, _a=0x67db010)
    at /usr/src/qgis/build/2.8/src/gui/layertree/moc_qgslayertreemapcanvasbridge.cxx:74
#_13 0x00007f6f74a0ac1e in QObject::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#_14 0x00007f6f73d8be2c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#_15 0x00007f6f73d924a0 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#_16 0x00007f6f75ea6223 in QgsApplication::notify (this=0x7fffec18c390, receiver=0x2ec5f80, event=0x67daf00)
    at /usr/src/qgis/qgis-2.8/src/core/qgsapplication.cpp:252
#_17 0x00007f6f749f24dd in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#_18 0x00007f6f749f5b3d in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#_19 0x00007f6f74a1ff83 in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#_20 0x00007f6f6f16de04 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#_21 0x00007f6f6f16e048 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#_22 0x00007f6f6f16e0ec in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


It's actually easy to reproduce for me. Just start qgis, select a TopoGeometry column (not registered in topology.layer) and "Add" --> crash.


  • assigned_to_id was configured as Sandro Santilli

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


I don't know if this could be related:

src/providers/postgres/qgspostgresconn.cpp: 903: (PQexec) [0ms] Not logged erroneous query: SELECT styleQML FROM layer_styles WHERE f_table_catalog
='nibio_test' AND f_table_schema='public' AND f_table_name='testing' AND f_geometry_column='tg' ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END,u
pdate_time DESC LIMIT 1 returned 7 [ERROR: relation "layer_styles" does not exist
LINE 1: SELECT styleQML FROM layer_styles WHERE f_table_catalog='nib...
^
]

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Jürgen Fischer (@jef-n)


  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Giovanni Manghi (@gioman)


  • priority_id was changed from Normal to High

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


To reproduce:

createdb bug13781
psql bug13781 <<EOF
create extension postgis;
create extension postgis_topology;
select createtopology('t');
create table t(id serial primary key);
select addtopogeometrycolumn('t','public','t','tg','point');
create table t2(id serial primary key, tg TopoGeometry);
insert into t2(tg) values ( (1,1,1,1) );
EOF

Then start qgis, Add PostGIS Layer, select public.t2, "Add".

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


NOTE: I've tested the crash to also happen with master branch from some weeks ago (a0a44f2)

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


Debug log seems interesting:

src/providers/postgres/qgspgtablemodel.cpp: 379: (layerURI) [16593ms] returning uri dbname='bug13781' port=5493 sslmode=disable key='""' srid=0 type=MultiPoint table="public"."t2" (tg) sql=
src/core/qgsmaplayer.cpp: 66: (QgsMapLayer) [1ms] original name: 't2'
src/core/qgsmaplayer.cpp: 68: (QgsMapLayer) [0ms] display name: 't2'
src/core/qgsvectorlayer.cpp: 585: (geometryType) [1ms] invalid layer or pointer to mDataProvider is null
src/core/qgsvectorlayer.cpp: 593: (geometryType) [0ms] WARNING: This code should never be reached. Problems may occur...

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


I see that QgsPostgresProvider::QgsPostgresProvider has lots of early returns. The crash happens because a QgsPostgresProvider does not have an associated connection (possibly due to these early returns).

Another bit of the output log shows this is a case of early return:

src/providers/postgres/qgspostgresprovider.cpp: 2847: (getGeometryDetails) [0ms] Spatial column type is TopoGeometry
src/core/qgsmessagelog.cpp: 45: (logMessage) [1ms] 2015-11-06T21:29:32 PostGIS[1] Could not find topology of layer 'public'.'t2'.'tg'
src/core/qgsmessagelog.cpp: 45: (logMessage) [0ms] 2015-11-06T21:29:32 PostGIS[1] invalid PostgreSQL topology layer
src/core/qgsproviderregistry.cpp: 370: (provider) [0ms] Instantiated the data provider plugin: postgres
src/core/qgsvectorlayer.cpp: 1378: (setDataProvider) [0ms] Instantiated the data provider plugin

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


Should a failed construction throw an exception rather than building partially ?

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


Found the issue: while mValid member is initialized to false, the call to QgsPostgresProvider::getGeometryDetails() sets it to true, then the "invalid PostgreSQL topology layer" condition fails to set it back to false

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


Confirmed, setting mValid=false when disconnecting the DB fixes this crash.
Should I provide a testcase for this ? Would it be "easy" to do in 2.8 branch ?


  • status_id was changed from Feedback to In Progress

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


Fixed in changeset "54cf972ac2334451e69d2171cc4f3e42da3880df".


  • status_id was changed from In Progress to Closed

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


Still needs to be fixed in trunk


  • status_id was changed from Closed to Reopened

@qgib
Copy link
Contributor Author

qgib commented Nov 6, 2015

Author Name: Sandro Santilli (@strk)


Fixed in changeset "65fb72a958c0d0cb0edce9c974cb6b2720d483b4".


  • status_id was changed from Reopened to Closed

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority Crash/Data Corruption labels May 25, 2019
@qgib qgib closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption High Priority
Projects
None yet
Development

No branches or pull requests

1 participant