Bug 444484 - Crash in stylechecker (due to stale ReferencedDUChainTopContext)
Summary: Crash in stylechecker (due to stale ReferencedDUChainTopContext)
Status: RESOLVED FIXED
Alias: None
Product: kdev-python
Classification: Developer tools
Component: Language support (show other bugs)
Version: git master
Platform: Neon Linux
: NOR crash
Target Milestone: ---
Assignee: Sven Brauch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-27 13:00 UTC by Jonathan Verner
Modified: 2021-10-28 21:46 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Verner 2021-10-27 13:00:20 UTC
When working on a python project, I occasionally get the following crashes coming from the stylechecker:


#0  Python::StyleChecking::addSetupErrorToContext(QString const&) (this=0x55555b4aede0, error="Got invalid size: stdin:5:1:")
    at /home/jonathan/zdroj/clones/kdev-python/pythonstylechecking.cpp:203
#1  0x00007fff319b6f97 in Python::StyleChecking::processOutputStarted() (this=0x55555b4aede0)
    at /home/jonathan/zdroj/clones/kdev-python/pythonstylechecking.cpp:139
#2  0x00007fff319b91bc in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (Python::StyleChecking::*)()>::call(void (Python::StyleChecking::*)(), Python::StyleChecking*, void**)
    (f=(void (Python::StyleChecking::*)(Python::StyleChecking * const)) 0x7fff319b6eae <Python::StyleChecking::processOutputStarted()>, o=0x55555b4aede0, arg=0x7fffffffce90) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:152


I only included the first three frames, since the function which crashes is called in response to a signal (QProcess::readyReadStandardOutput), so the rest of the trace is not interesting.

The crash is due to `m_stylechecker` being no longer valid at the point. The only way I see that can happen is due to some problem in the `kdevpythonsupport/codestyle.py`
script which leads it to output more stuff then expected or take too long outputting it. That way, the `processOutputStarted` function would read the output up to the expected size (or up to what it can read in 100ms) and then set the `m_currentlyChecking` to nullptr. However, when the script outputs some more after this, `processOutputStarted` is called again, now with `m_currentlyChecking` null which eventually leads to a crash (note also, that when its called again, `m_mutex` is probably not held anymore, so there might be other races).|
Comment 1 Sven Brauch 2021-10-27 19:32:22 UTC
Thanks for the report. Looking at this code, I agree that several things are wrong.

If we get around to fixing kdev-python for Python 3.10, we should definitely have a look here as well...
Comment 2 Bug Janitor Service 2021-10-28 21:16:32 UTC
A possibly relevant merge request was started @ https://invent.kde.org/kdevelop/kdev-python/-/merge_requests/14
Comment 3 Jonathan Verner 2021-10-28 21:46:13 UTC
Git commit a0b9d197e7da2f4484ac63cb32faf53817e3d465 by Jonathan L. Verner.
Committed on 28/10/2021 at 21:15.
Pushed by brauch into branch 'master'.

When codestyle.py outputs too slowly (or unexpectedly), restart it instead of crashing.

When the `codestyle.py` is too slow in outputting data, the
`processOutputStarted` function might miss them, release the
`m_mutex` lock and set `m_stylechecker` to nullptr.

When the data then later arrives, processOutputStarted is called
again, however without `m_mutex` being held and `m_stylechecker`
no longer valid. This eventually leads to a crash when dereferencing
`m_stylechecker`.

The current commit tries to fix this by checking that `m_mutex` is
held at the start of `processOutputStarted`. If it is not, then we are
in the "late data case". However, in this situation, we do not know
the amount of data that should still arrive and basically the only
way to solve the situation, is to kill the server (and start it again
on the next run). So that is what we do.

M  +15   -0    pythonstylechecking.cpp

https://invent.kde.org/kdevelop/kdev-python/commit/a0b9d197e7da2f4484ac63cb32faf53817e3d465