Kormil / harbour-powietrze

Application for checking the current state of air quality for Sailfish OS
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

Enabling OpenAQ provider causes a segfault #19

Open llewelld opened 3 years ago

llewelld commented 3 years ago

Using the OpenAQ provide causes a segfault on my device. The Powietrze provider works fine; I wasn't able to test Airly as I don't have an API key to hand.

The following steps are sufficient to trigger the segfault here:

  1. Open the app.
  2. Pulley menu > "Settings"
  3. Select "Manage providers"
  4. Select "OpenAQ"
  5. Set OpenAQ to "Enabled"
  6. Swipe back to the Providers page.
  7. Swipe back to the Settings page.
  8. Swipe back to main page.
  9. Pulley meny > "Select station"
  10. Select "OpenAQ"
  11. Select any country (e.g. "Afghanistan")

At this point the app crashes with a segfault. It's repeatable every time.

The backtrace doesn't look very helpful, but maybe you can extract something useful from it:

Thread 1 "harbour-powietr" received signal SIGSEGV, Segmentation fault.
0x0000007fbe9fcbe0 in QJsonObject::valueAt(int) const () from /usr/lib64/libQt5Core.so.5
(gdb) bt
#0  0x0000007fbe9fcbe0 in QJsonObject::valueAt(int) const () from /usr/lib64/libQt5Core.so.5
#1  0x0000007fbea01f84 in QJsonValueRef::toValue() const () from /usr/lib64/libQt5Core.so.5
#2  0x0000007fbea02064 in QJsonValueRef::toArray() const () from /usr/lib64/libQt5Core.so.5
#3  0x0000005555594fdc in ?? ()
#4  0x0000005555598164 in ?? ()
#5  0x0000007fbea48204 in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib64/libQt5Core.so.5
#6  0x00000055555b56a4 in ?? ()
#7  0x000000555559f6f0 in ?? ()
#8  0x000000555559f82c in ?? ()
#9  0x0000007fbea48204 in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib64/libQt5Core.so.5
#10 0x0000007fbed0ac08 in ?? () from /usr/lib64/libQt5Network.so.5
#11 0x0000007fbeda0544 in ?? () from /usr/lib64/libQt5Network.so.5
#12 0x0000007fbea48c6c in QObject::event(QEvent*) () from /usr/lib64/libQt5Core.so.5
#13 0x0000007fbea1e144 in QCoreApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#14 0x0000007fbea1e2e8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#15 0x0000007fbea206b8 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQt5Core.so.5
#16 0x0000007fbea70648 in ?? () from /usr/lib64/libQt5Core.so.5
#17 0x0000007fbd816234 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
#18 0x0000007fbd8164a0 in ?? () from /usr/lib64/libglib-2.0.so.0
#19 0x0000007fbd816534 in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
#20 0x0000007fbea70a90 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQt5Core.so.5
#21 0x0000007fbea1c608 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQt5Core.so.5
#22 0x0000007fbea241d4 in QCoreApplication::exec() () from /usr/lib64/libQt5Core.so.5
#23 0x0000005555569d2c in main ()
(gdb) 

After having been through these steps the app will then crash on startup with matching backtrace. I was able to start the app again by editing .config/harbour-powietrze/harbour-powietrze.conf and changing OpenAQ\enabled=true to OpenAQ\enabled=false.

I'll try to debug further if I get the chance.

Kormil commented 3 years ago

Hi, I will be very grateful if you could check this one.

very promising version.tar.gz

llewelld commented 3 years ago

I'm afraid no joy with the new version, it still crashes when configured to use OpenAQ. However, I built a new version based on the latest master branch with debug symbols and was able to get a better backtrace. Hopefully this helps narrow down the problem.

Thread 1 "harbour-powietr" received signal SIGSEGV, Segmentation fault.
0x0000007fbe9fcbe0 in QJsonObject::valueAt(int) const () from /usr/lib64/libQt5Core.so.5
(gdb) bt
#0  0x0000007fbe9fcbe0 in QJsonObject::valueAt(int) const () from /usr/lib64/libQt5Core.so.5
#1  0x0000007fbea01f84 in QJsonValueRef::toValue() const () from /usr/lib64/libQt5Core.so.5
#2  0x0000007fbea02064 in QJsonValueRef::toArray() const () from /usr/lib64/libQt5Core.so.5
#3  0x0000005555594f9c in OpenAQConnection::readStationsFromJson (this=this@entry=0x555567a380, 
    jsonDocument=...) at src/connection/openaqconnection.cpp:315
#4  0x00000055555961b8 in OpenAQConnection::<lambda(Request::Status, const QByteArray&)>::operator() (
    responseArray=..., status=<optimized out>, __closure=0x7fac028210)
    at src/connection/openaqconnection.cpp:225
#5  QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1>, QtPrivate::List<Request::Status, const QByteArray&>, void, OpenAQConnection::getNearestStations(QGeoCoordinate, float, std::function<void(std::shared_ptr<StationList>)>)::<lambda(Request::Status, const QByteArray&)> >::call (arg=<optimized out>, f=...)
    at /usr/include/qt5/QtCore/qobjectdefs_impl.h:495
#6  QtPrivate::Functor<OpenAQConnection::getNearestStations(QGeoCoordinate, float, std::function<void(std::shared_ptr<StationList>)>)::<lambda(Request::Status, const QByteArray&)>, 2>::call<QtPrivate::List<Request::Status, QByteArray const&>, void> (arg=<optimized out>, f=...)
    at /usr/include/qt5/QtCore/qobjectdefs_impl.h:552
#7  QtPrivate::QFunctorSlotObject<OpenAQConnection::getNearestStations(QGeoCoordinate, float, std::function<void(std::shared_ptr<StationList>)>)::<lambda(Request::Status, const QByteArray&)>, 2, QtPrivate::List<Request::Status, const QByteArray&>, void>::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void **, bool *)
    (which=<optimized out>, this_=0x7fac028200, r=<optimized out>, a=<optimized out>, ret=<optimized out>)
    at /usr/include/qt5/QtCore/qobject_impl.h:192
#8  0x0000007fbea48204 in QMetaObject::activate(QObject*, int, int, void**) ()
   from /usr/lib64/libQt5Core.so.5
#9  0x00000055555b5a34 in Request::finished (this=this@entry=0x5555bfa6d0, _t1=<optimized out>, 
    _t1@entry=Request::SUCCESS, _t2=...) at moc_connection.cpp:154
#10 0x000000555559fa80 in Request::responseFinished (error=QNetworkReply::NoError, errorString=..., 
    this=0x5555bfa6d0) at src/connection/connection.cpp:69
#11 Request::responseFinished (this=0x5555bfa6d0, error=<optimized out>, errorString=...)
    at src/connection/connection.cpp:55
#12 0x000000555559fbbc in Request::<lambda()>::operator() (__closure=0x5555be4680)
    at src/connection/connection.cpp:29
#13 QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, Request::run()::<lambda()> >::call (arg=<optimized out>, f=...) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:495
#14 QtPrivate::Functor<Request::run()::<lambda()>, 0>::call<QtPrivate::List<>, void> (arg=<optimized out>, 
    f=...) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:552
#15 QtPrivate::QFunctorSlotObject<Request::run()::<lambda()>, 0, QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void **, bool *) (which=<optimized out>, this_=0x5555be4670, 
    r=<optimized out>, a=<optimized out>, ret=<optimized out>)
    at /usr/include/qt5/QtCore/qobject_impl.h:192
#16 0x0000007fbea48204 in QMetaObject::activate(QObject*, int, int, void**) ()
   from /usr/lib64/libQt5Core.so.5
#17 0x0000007fbed0ac08 in ?? () from /usr/lib64/libQt5Network.so.5
#18 0x0000007fbeda0544 in ?? () from /usr/lib64/libQt5Network.so.5
#19 0x0000007fbea48c6c in QObject::event(QEvent*) () from /usr/lib64/libQt5Core.so.5
#20 0x0000007fbea1e144 in QCoreApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#21 0x0000007fbea1e2e8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) ()
   from /usr/lib64/libQt5Core.so.5
#22 0x0000007fbea206b8 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
   from /usr/lib64/libQt5Core.so.5
#23 0x0000007fbea70648 in ?? () from /usr/lib64/libQt5Core.so.5
#24 0x0000007fbd816234 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
#25 0x0000007fbd8164a0 in ?? () from /usr/lib64/libglib-2.0.so.0
#26 0x0000007fbd816534 in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
#27 0x0000007fbea70a90 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib64/libQt5Core.so.5
#28 0x0000007fbea1c608 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib64/libQt5Core.so.5
#29 0x0000007fbea241d4 in QCoreApplication::exec() () from /usr/lib64/libQt5Core.so.5
#30 0x0000005555569e4c in main (argc=<optimized out>, argv=<optimized out>) at src/harbour-powietrze.cpp:45
(gdb) 

This shows a problem happening at src/connection/openaqconnection.cpp:315, however this doesn't seem to be where the real issue is. The JSON is coming through correctly. Here's a snippet of it:

{
    "meta": {
        "found": 3,
        "license": "CC BY 4.0d",
        "limit": 1000,
        "name": "openaq-api",
        "page": 1,
        "website": "https://u50g7n0cbj.execute-api.us-east-1.amazonaws.com/"
    },
    "results": [
        {
            "city": "Pirkanmaa",
            "coordinates": {
                "latitude": 61.499099999550197,
                "longitude": 23.802209999999999
            },

When I add debugs to print out a copy of this JSON data the problem moves to readCountriesFromJson, so I suspect it's a timing issue, maybe with something getting destroyed while still being used?

Kormil commented 3 years ago

Thank you for tests and descriptions. Unfortunately I still cannot reproduce this case :( but your advice was very helpful so I've made small changes. I hope it will start working now. Could you retest it? All changes are pushed to repository, and I build package for you too.

RPMS.tar.gz