strawberrymusicplayer / strawberry

:strawberry: Strawberry Music Player
https://www.strawberrymusicplayer.org/
GNU General Public License v3.0
2.74k stars 192 forks source link

Program crashes when typing too fast in search box #1095

Closed cproensa closed 1 year ago

cproensa commented 1 year ago

Describe the bug Program crashes when typing too fast in search box

To Reproduce Using Strawberry as client for a subsonic library. When typing in the search box for the subsonic library, if the input is written too fast, for characters that will match an item, the program crashes. Looks like, if a new character is typed before the previous partial search is rendered, something goes wrong...

Expected behavior Not a crash lol

Screenshots: N/A

System Information:

Additional context Subsonic collection is >200k files, so a small delay happens when searching. May not be reproducible with small enough collections. I dont have the files in local storage, so i can not test the search for local collection.

jonaski commented 1 year ago

Can you do a gdb backtrace? See https://wiki.strawberrymusicplayer.org/wiki/Backtrace Install the latest debug-mingw release from https://builds.strawberrymusicplayer.org/windows/

cproensa commented 1 year ago

Installed: StrawberrySetup-1.0.12.10.gdb55f314-Debug-mingw-x64.exe When running within gdb, the issue is not reproducible. However, when running directly the exe, it still happens...

Any tips?

edit: also installed in linux with: strawberry-dbgsym_1.0.12-10-gdb55f314-jammy_amd64.ddeb no issues there...

cproensa commented 1 year ago

The breaking point is v0.9.3

Same behaviour with QT5 variants

jonaski commented 1 year ago

Does it crash with the MSVC version too?

Can you paste what's shown for the crash from the Windows logs (Control Panel / All Control Panel Items / Administrative Tools Event Viewer / Windows Logs / Application). There should be an entry for the last crash. At least this could give an idea as to what sort of crash it is.

Try running strawberry.exe from the debug version from the Command prompt (without GDB), does it crash? If it still crashes there could be some output to the console with the debug version that might be helpful in debugging the issue.

Do you have any 3rdparty programs that "hooks" to windows, like those that come with wide screen monitors? If so try quitting them before running strawberry to see if they solve the crash. If you have any antivirus software try temporary disabling them.

The only relevant change between 0.9.2 and 0.9.3 that I see is commit 5a58ac2845c99c5cb58e84b3b01787f01c7ec399 where CollectionModel::RunQuery was changed, that's what's run to query the DB each time you search. Threading is different on Linux and Windows, so it could be causing issues on Windows and not Linux. But this is just a guess.

cproensa commented 1 year ago

Does it crash with the MSVC version too?

MSV is the release i have been using so far. Can't try the debug msvc version, because it asks for some MSVCP dlls, which is not fixed even after installing the VS-redist packages from MS...

Do you have any 3rdparty programs that "hooks" to windows, like those that come with wide screen monitors? if you have any antivirus software try temporary disabling them.

Nothing special here... not using AV other than Windows default stuff. I have installed release 1.0.12 in a different Windows PC, which is as clean as can be (as i never use it...). And the crash happens too.

Try running strawberry.exe from the debug version from the Command prompt (without GDB), does it crash?

Yes, running directly (without gdb) behaves as badly as the standard programs. I can crash it with a single search. Nothing is printed in console. Console has output while running, info, etc, but nothing new at the moment i am searching and breaking it.

Can you paste what's shown for the crash from the Windows logs

Not a lot of info, really: imagen

Now, running the debug version in gdb, and bashing hard on that search box, i finally managed to get some messages:

These ones, but the app still runs:

00:59:38.928 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
00:59:39.179 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
00:59:39.438 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
00:59:39.691 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
00:59:39.958 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
00:59:40.210 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
01:00:08.960 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
01:00:09.148 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
01:00:09.222 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
01:00:09.295 ERROR CollectionModel::Grouping:1913   CollectionModel::Grouping[] index out of range -17891601
...

And also this one, which halts the application:

Thread 33 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 17780.0x1d94]
0x00007ff65e17e6e3 in CollectionModel::RunQuery (this=0x1eefaaa1e20, parent=0x1eefebe1060) at /persistent-data/mingw/windows-debug-x64/source/src/collection/collectionmodel.cpp:849
849     /persistent-data/mingw/windows-debug-x64/source/src/collection/collectionmodel.cpp: No such file or directory.
(gdb)

(gdb) bt
#0  0x00007ff65e17e6e3 in CollectionModel::RunQuery (this=0x1eefaaa1e20, parent=0x1eefebe1060)
    at /persistent-data/mingw/windows-debug-x64/source/src/collection/collectionmodel.cpp:849
#1  0x00007ff65e8b5f38 in std::__invoke_impl<CollectionModel::QueryResult, CollectionModel::QueryResult (CollectionModel::*&)(CollectionItem*), CollectionModel*&, CollectionItem*&> (
    __f=@0xb8cd9ff9a0: (CollectionModel::QueryResult (CollectionModel::*)(CollectionModel * const, CollectionItem *)) 0x7ff65e17e49c <CollectionModel::RunQuery(CollectionItem*)>, __t=@0xb8cd9ff9e8: 0x1eefaaa1e20)
    at /persistent-data/mingw/mxe-debug/source/usr/lib/gcc/x86_64-w64-mingw32.shared/12.2.0/include/c++/bits/invoke.h:74
#2  0x00007ff65e8fa8f3 in std::__invoke<CollectionModel::QueryResult (CollectionModel::*&)(CollectionItem*), CollectionModel*&, CollectionItem*&> (
    __fn=@0xb8cd9ff9a0: (CollectionModel::QueryResult (CollectionModel::*)(CollectionModel * const, CollectionItem *)) 0x7ff65e17e49c <CollectionModel::RunQuery(CollectionItem*)>)
    at /persistent-data/mingw/mxe-debug/source/usr/lib/gcc/x86_64-w64-mingw32.shared/12.2.0/include/c++/bits/invoke.h:97
#3  0x00007ff65e8ea0fb in std::invoke<CollectionModel::QueryResult (CollectionModel::*&)(CollectionItem*), CollectionModel*&, CollectionItem*&> (
    __fn=@0xb8cd9ff9a0: (CollectionModel::QueryResult (CollectionModel::*)(CollectionModel * const, CollectionItem *)) 0x7ff65e17e49c <CollectionModel::RunQuery(CollectionItem*)>)
    at /persistent-data/mingw/mxe-debug/source/usr/lib/gcc/x86_64-w64-mingw32.shared/12.2.0/include/c++/functional:111
#4  0x00007ff65e90df77 in QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*)#1}::operator()(CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*) const (__closure=0xb8cd9ffb8f,
    function=(CollectionModel::QueryResult (CollectionModel::*)(CollectionModel * const, CollectionItem *)) 0x7ff65e17e49c <CollectionModel::RunQuery(CollectionItem*)>, args#0=0x1eefaaa1e20, args#1=0x1eefebe1060)
    at /persistent-data/mingw/mxe-debug/source/usr/x86_64-w64-mingw32.shared/qt6/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:116
#5  0x00007ff65e8b5e9c in std::__invoke_impl<CollectionModel::QueryResult, QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>(std::__invoke_other, QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, CollectionModel::QueryResult (CollectionModel::*&&)(CollectionItem*), CollectionModel*&&, CollectionItem*&&) (__f=...)
    at /persistent-data/mingw/mxe-debug/source/usr/lib/gcc/x86_64-w64-mingw32.shared/12.2.0/include/c++/bits/invoke.h:61
#6  0x00007ff65e8f9daa in std::__invoke<QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>(QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, CollectionModel::QueryResult (CollectionModel::*&&)(CollectionItem*), CollectionModel*&&, CollectionItem*&&) (__fn=...)
    at /persistent-data/mingw/mxe-debug/source/usr/lib/gcc/x86_64-w64-mingw32.shared/12.2.0/include/c++/bits/invoke.h:97
#7  0x00007ff65e8ac8a4 in std::__apply_impl<QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, std::tuple<CollectionModel::QueryResult --Type <RET> for more, q to quit, c to continue without paging--
(CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>, 0ull, 1ull, 2ull>(QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, std::tuple<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>&&, std::integer_sequence<unsigned long long, 0ull, 1ull, 2ull>) (__f=..., __t=...)
    at /persistent-data/mingw/mxe-debug/source/usr/lib/gcc/x86_64-w64-mingw32.shared/12.2.0/include/c++/tuple:1853
#8  0x00007ff65e8e8ee8 in std::apply<QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, std::tuple<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*> >(QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor()::{lambda(CollectionModel::QueryResult (CollectionModel::* const&)(CollectionItem*), CollectionModel*, CollectionItem*)#1}, std::tuple<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>&&) (__f=...,
    __t=...)
    at /persistent-data/mingw/mxe-debug/source/usr/lib/gcc/x86_64-w64-mingw32.shared/12.2.0/include/c++/tuple:1865
#9  0x00007ff65e4a5085 in QtConcurrent::StoredFunctionCall<CollectionModel::QueryResult (CollectionModel::*)(CollectionItem*), CollectionModel*, CollectionItem*>::runFunctor (this=0x1eefd3a4e20)
    at /persistent-data/mingw/mxe-debug/source/usr/x86_64-w64-mingw32.shared/qt6/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:122
#10 0x00007ff65e4a7e43 in QtConcurrent::RunFunctionTaskBase<CollectionModel::QueryResult>::run (this=0x1eefd3a4e20)
    at /persistent-data/mingw/mxe-debug/source/usr/x86_64-w64-mingw32.shared/qt6/include/QtConcurrent/qtconcurrentrunbase.h:83
#11 0x00007ffd38394a17 in QThreadPoolThread::run (this=0x1eef79cc720)
    at ../qtbase-everywhere-src-6.4.1/src/corelib/thread/qthreadpool.cpp:66
#12 0x00007ffd38391688 in QThreadPrivate::start (arg=0x1eef79cc720)
    at ../qtbase-everywhere-src-6.4.1/src/corelib/thread/qthread_win.cpp:290
#13 0x00007ffdc49c7614 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#14 0x00007ffdc62426a1 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#15 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

The only relevant change between 0.9.2 and 0.9.3 that I see is commit https://github.com/strawberrymusicplayer/strawberry/commit/5a58ac2845c99c5cb58e84b3b01787f01c7ec399 where CollectionModel::RunQuery was changed, that's what's run to query the DB each time you search.

this one: 74b7738a9d2d0570ac422a72732755ef3f76e90e also has something about "threads", but idk...

jonaski commented 1 year ago

Thanks for the debugging, the backtrace helps, it crashes because I moved the mutex in 5a58ac2845c99c5cb58e84b3b01787f01c7ec399, but the code was bad before that too, I'll work on a fix.

jonaski commented 1 year ago

This should hopefully be fixed now. 1.0.12.18.gb5fa401d or later has the fix. Can you test with the latest from https://builds.strawberrymusicplayer.org/windows/

cproensa commented 1 year ago

Can you test with the latest from https://builds.strawberrymusicplayer.org/windows/

Looks like its working fine now. Thanks for your quick fix!