Bug report #13781

Segfault on adding TopoGeometry column

Added by Sandro Santilli about 9 years ago. Updated about 9 years ago.

Status:Closed
Priority:High
Assignee:Sandro Santilli
Category:-
Affected QGIS version:2.8.3 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:21807

Description

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

Associated revisions

Revision 54cf972a
Added by Sandro Santilli about 9 years ago

Properly set invalid topology layer as invalid

Fixes #13781 (crash)

Revision 65fb72a9
Added by Sandro Santilli about 9 years ago

Properly set invalid topology layer as invalid

Fixes #13781 (crash)

(cherry-picked from 54cf972ac2334451e69d2171cc4f3e42da3880df)

History

#1 Updated by Sandro Santilli about 9 years ago

  • Assignee set to Sandro Santilli

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

#2 Updated by Sandro Santilli about 9 years ago

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...
^
]

#3 Updated by Jürgen Fischer about 9 years ago

  • Status changed from Open to Feedback

#4 Updated by Giovanni Manghi about 9 years ago

  • Priority changed from Normal to High

#5 Updated by Sandro Santilli about 9 years ago

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".

#6 Updated by Sandro Santilli about 9 years ago

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

#7 Updated by Sandro Santilli about 9 years ago

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...

#8 Updated by Sandro Santilli about 9 years ago

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 PostGIS1 Could not find topology of layer 'public'.'t2'.'tg'
src/core/qgsmessagelog.cpp: 45: (logMessage) [0ms] 2015-11-06T21:29:32 PostGIS1 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

#9 Updated by Sandro Santilli about 9 years ago

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

#10 Updated by Sandro Santilli about 9 years ago

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

#11 Updated by Sandro Santilli about 9 years ago

  • Status changed from Feedback to In Progress

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 ?

#12 Updated by Sandro Santilli about 9 years ago

  • Status changed from In Progress to Closed

#13 Updated by Sandro Santilli about 9 years ago

  • Status changed from Closed to Reopened

Still needs to be fixed in trunk

#14 Updated by Sandro Santilli about 9 years ago

  • Status changed from Reopened to Closed

Also available in: Atom PDF