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

Crash when opening the database #8

Closed
aleixpol opened this issue Oct 11, 2015 · 7 comments
Closed

Crash when opening the database #8

aleixpol opened this issue Oct 11, 2015 · 7 comments
Assignees
Labels

Comments

@aleixpol
Copy link
Collaborator

I fixed the db lookup bug, it was due to having 2 libappstream.so on the system, it worked by specifying the LD_LIBRARY_PATH (without using sudo).

Now, with the proper libraries, I get such a crash when opening the db.

$ gdb --args appstreamcli search kalgebra
Reading symbols from appstreamcli...done.
(gdb) r
Starting program: /home/kde-devel/kde5/bin/appstreamcli search kalgebra
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi

Program received signal SIGABRT, Aborted.
0x00007ffff60445f8 in raise () from /usr/lib/libc.so.6
(gdb) where
#0  0x00007ffff60445f8 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff6045a7a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff4e53b3d in __gnu_cxx::__verbose_terminate_handler () at /build/gcc/src/gcc-5.2.0/libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x00007ffff4e51996 in __cxxabiv1::__terminate (handler=<optimized out>) at /build/gcc/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4  0x00007ffff4e519e1 in std::terminate () at /build/gcc/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5  0x00007ffff4e51bf8 in __cxxabiv1::__cxa_throw (obj=obj@entry=0x637690, tinfo=0x7ffff5138aa8 <typeinfo for std::invalid_argument>, 
    dest=0x7ffff4e67140 <std::invalid_argument::~invalid_argument()>) at /build/gcc/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_throw.cc:87
#6  0x00007ffff4e7a9df in std::__throw_invalid_argument (__s=0x7ffff6fe5ed9 "stoi") at /build/gcc/src/gcc-5.2.0/libstdc++-v3/src/c++11/functexcept.cc:82
#7  0x00007ffff6fcb8c2 in __gnu_cxx::__stoa<long, int, char, int> (__convf=0x7ffff60482a0 <strtoq>, __name=0x7ffff6fe5ed9 "stoi", 
    __str=0x7ffff5145218 <std::string::_Rep::_S_empty_rep_storage+24> "", __idx=0x0) at /usr/include/c++/5.2.0/ext/string_conversions.h:65
#8  0x00007ffff6fcb759 in std::stoi (__str="", __idx=0x0, __base=10) at /usr/include/c++/5.2.0/bits/basic_string.h:5258
#9  0x00007ffff6fc79a5 in DatabaseRead::open (this=0x629670, dbPath=0x6296b0 "/var/cache/app-info/xapian/default")
    at /home/kde-devel/frameworks/appstream/src/xapian/database-read.cpp:66
#10 0x00007ffff6fd1009 in xa_database_read_open (db=0x629670, db_path=0x6296b0 "/var/cache/app-info/xapian/default")
    at /home/kde-devel/frameworks/appstream/src/xapian/database-cwrap.cpp:33
#11 0x00007ffff6fdbfa6 in as_database_real_open (db=0x62a020) at /home/kde-devel/frameworks/appstream/src/as-database.c:105
#12 0x00007ffff6fdc011 in as_database_open (db=0x62a020) at /home/kde-devel/frameworks/appstream/src/as-database.c:117
#13 0x0000000000404257 in ascli_search_component (dbpath=0x0, search_term=0x7fffffffe7bb "kalgebra", detailed=0) at /home/kde-devel/frameworks/appstream/tools/ascli-mdata-actions.c:157
#14 0x0000000000403244 in as_client_run (argv=0x7fffffffe468, argc=3) at /home/kde-devel/frameworks/appstream/tools/appstream-cli.c:151
#15 0x0000000000403482 in main (argc=3, argv=0x7fffffffe468) at /home/kde-devel/frameworks/appstream/tools/appstream-cli.c:199
@ximion
Copy link
Owner

ximion commented Oct 11, 2015

Looks like the database version is set incorrectly. I will catch the error on string conversion, but we should also check why the version number is wrong.
Can you please apply this patch, run appstreamcli with the --verbose flag and tell me what it says about the schema version?

--- a/src/xapian/database-read.cpp
+++ b/src/xapian/database-read.cpp
@@ -63,6 +63,8 @@ DatabaseRead::open (const gchar *dbPath)
        if (m_dbLocale.empty ())
                m_dbLocale = "C";

+       g_debug ("Read DB schema version: %s", m_xapianDB.get_metadata ("db-schema-version").c_str ());
+
        m_schemaVersion = stoi (m_xapianDB.get_metadata ("db-schema-version"));
        if (m_schemaVersion != AS_DB_SCHEMA_VERSION) {
                g_warning ("Attempted to open an old version of the AppStream cache. Please refresh the cache and try again!");

@aleixpol
Copy link
Collaborator Author

It seems empty.
If I add this debug: g_warning ("Read DB schema version: ::%s::%s::", m_xapianDB.get_metadata ("db-schema-version").c_str (), m_dbLocale.c_str());
I get: ** (appstreamcli:25873): WARNING **: Read DB schema version: ::::C::

ximion added a commit that referenced this issue Oct 13, 2015
This should resolve issue #8, but doesn't fix the root cause of it
(which is that the database metadata field holding the schema version is
apparently empty)
@ximion ximion added the bug label Oct 13, 2015
@ximion ximion self-assigned this Oct 13, 2015
@ximion
Copy link
Owner

ximion commented Oct 13, 2015

Okay, so the crash should be gone now, let's fix the root cause of this issue.
With which compiler and with which version of it did you compile the code? We use the new C++11 method to_string() to convert an int into a std::string for storage as metadata - maybe that doesn't work for some reason.

@aleixpol
Copy link
Collaborator Author

apol@oliver:~$ gcc --version
gcc (GCC) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@ximion
Copy link
Owner

ximion commented Oct 13, 2015

Okay, that looks sane - could you run the unit tests please, and see if the database test fails?
(make && make test)

@aleixpol
Copy link
Collaborator Author

It passes now after the last changes in master, also appstream search works now. I'll close the issue.

@ximion
Copy link
Owner

ximion commented Oct 13, 2015

Maybe this was an artifact of the mix of different AppStream libraries in the past...
Glad it's working now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants