Bug 403038 - KWin crashes (occasionally) when running script to minimize current open window
Summary: KWin crashes (occasionally) when running script to minimize current open window
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: general (show other bugs)
Version: 5.14.5
Platform: Archlinux Linux
: NOR crash (vote)
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: drkonqi
Depends on:
Blocks:
 
Reported: 2019-01-09 13:28 UTC by beojan
Modified: 2019-02-22 14:54 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.15.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description beojan 2019-01-09 13:28:20 UTC
Application: kwin_x11 (5.14.5)

Qt Version: 5.12.0
Frameworks Version: 5.53.0
Operating System: Linux 4.19.12-1-ck x86_64
Distribution: "Arch Linux"

-- Information about the crash:
The script is below:

```
NUM=$(qdbus org.kde.KWin /Scripting org.kde.kwin.Scripting.loadScript /home/beojan/.local/share/plasmashell/minimize.js Minimize)
qdbus org.kde.KWin /$NUM org.kde.kwin.Scripting.run
qdbus org.kde.KWin /Scripting  org.kde.kwin.Scripting.unloadScript Minimize
```

And the KWin script is:

```
workspace.activeClient.minimized = true;
```

The crash can be reproduced sometimes.

-- Backtrace:
Application: KWin (kwin_x11), signal: Segmentation fault
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[Current thread is 1 (Thread 0x7f0463fe7840 (LWP 28362))]

Thread 7 (Thread 0x7f04609ea700 (LWP 8746)):
[KCrash Handler]
#6  0x00007f046bc36b60 in QRingBuffer::chop(long long) () at /usr/lib/libQt5Core.so.5
#7  0x00007f046bcc45f2 in QIODevicePrivate::read(char*, long long, bool) () at /usr/lib/libQt5Core.so.5
#8  0x00007f046bcc51fe in QIODevice::readAll() () at /usr/lib/libQt5Core.so.5
#9  0x00007f046cfe105f in  () at /usr/lib/libkwin.so.5
#10 0x00007f046cfe2341 in  () at /usr/lib/libkwin.so.5
#11 0x00007f046bbc39a1 in  () at /usr/lib/libQt5Core.so.5
#12 0x00007f046bbbf9cc in  () at /usr/lib/libQt5Core.so.5
#13 0x00007f046a9a6a9d in start_thread () at /usr/lib/libpthread.so.0
#14 0x00007f046d22cb23 in clone () at /usr/lib/libc.so.6

Thread 6 (Thread 0x7f0445f38700 (LWP 28495)):
#0  0x00007f046a9acafc in pthread_cond_wait@@GLIBC_2.3.2 () at /usr/lib/libpthread.so.0
#1  0x00007f046b6a928c in  () at /usr/lib/libQt5Script.so.5
#2  0x00007f046b6a92a9 in  () at /usr/lib/libQt5Script.so.5
#3  0x00007f046a9a6a9d in start_thread () at /usr/lib/libpthread.so.0
#4  0x00007f046d22cb23 in clone () at /usr/lib/libc.so.6

Thread 5 (Thread 0x7f0447fff700 (LWP 28493)):
#0  0x00007f046a9acafc in pthread_cond_wait@@GLIBC_2.3.2 () at /usr/lib/libpthread.so.0
#1  0x00007f0458b80c24 in  () at /usr/lib/dri/i965_dri.so
#2  0x00007f0458b80948 in  () at /usr/lib/dri/i965_dri.so
#3  0x00007f046a9a6a9d in start_thread () at /usr/lib/libpthread.so.0
#4  0x00007f046d22cb23 in clone () at /usr/lib/libc.so.6

Thread 4 (Thread 0x7f045b4f0700 (LWP 28491)):
#0  0x00007f046d221d16 in ppoll () at /usr/lib/libc.so.6
#1  0x00007f046bdcd46b in qt_safe_poll(pollfd*, unsigned long, timespec const*) () at /usr/lib/libQt5Core.so.5
#2  0x00007f046bdce94b in QEventDispatcherUNIX::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#3  0x00007f046bd7a58c in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#4  0x00007f046bbbe5c9 in QThread::exec() () at /usr/lib/libQt5Core.so.5
#5  0x00007f046a166b89 in  () at /usr/lib/libQt5Qml.so.5
#6  0x00007f046bbbf9cc in  () at /usr/lib/libQt5Core.so.5
#7  0x00007f046a9a6a9d in start_thread () at /usr/lib/libpthread.so.0
#8  0x00007f046d22cb23 in clone () at /usr/lib/libc.so.6

Thread 3 (Thread 0x7f04612ee700 (LWP 28413)):
#0  0x00007f046d221d16 in ppoll () at /usr/lib/libc.so.6
#1  0x00007f046bdcd46b in qt_safe_poll(pollfd*, unsigned long, timespec const*) () at /usr/lib/libQt5Core.so.5
#2  0x00007f046bdce94b in QEventDispatcherUNIX::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#3  0x00007f046bd7a58c in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#4  0x00007f046bbbe5c9 in QThread::exec() () at /usr/lib/libQt5Core.so.5
#5  0x00007f0469bd3ba6 in  () at /usr/lib/libQt5DBus.so.5
#6  0x00007f046bbbf9cc in  () at /usr/lib/libQt5Core.so.5
#7  0x00007f046a9a6a9d in start_thread () at /usr/lib/libpthread.so.0
#8  0x00007f046d22cb23 in clone () at /usr/lib/libc.so.6

Thread 2 (Thread 0x7f046367b700 (LWP 28412)):
#0  0x00007f046d221c21 in poll () at /usr/lib/libc.so.6
#1  0x00007f046bae3630 in  () at /usr/lib/libxcb.so.1
#2  0x00007f046bae52db in xcb_wait_for_event () at /usr/lib/libxcb.so.1
#3  0x00007f0463b7196b in  () at /usr/lib/libQt5XcbQpa.so.5
#4  0x00007f046bbbf9cc in  () at /usr/lib/libQt5Core.so.5
#5  0x00007f046a9a6a9d in start_thread () at /usr/lib/libpthread.so.0
#6  0x00007f046d22cb23 in clone () at /usr/lib/libc.so.6

Thread 1 (Thread 0x7f0463fe7840 (LWP 28362)):
#0  0x00007f046a9acafc in pthread_cond_wait@@GLIBC_2.3.2 () at /usr/lib/libpthread.so.0
#1  0x00007f046bae383b in  () at /usr/lib/libxcb.so.1
#2  0x00007f046bae4fef in  () at /usr/lib/libxcb.so.1
#3  0x00007f046bae5103 in xcb_wait_for_reply () at /usr/lib/libxcb.so.1
#4  0x00007f0460a97ea0 in KWin::X11Cursor::doGetPos() () at /usr/lib/qt/plugins/org.kde.kwin.platforms/KWinX11Platform.so
#5  0x00007f046cef192a in KWin::Cursor::pos() () at /usr/lib/libkwin.so.5
#6  0x00007f046cf45ee0 in KWin::Screens::current() const () at /usr/lib/libkwin.so.5
#7  0x00007f046cf967f4 in KWin::Toplevel::isOnActiveScreen() const () at /usr/lib/libkwin.so.5
#8  0x00007f046cf5e2e0 in KWin::Workspace::takeActivity(KWin::AbstractClient*, QFlags<KWin::Workspace::ActivityFlag>) () at /usr/lib/libkwin.so.5
#9  0x00007f046cec5520 in KWin::Workspace::delayFocus() () at /usr/lib/libkwin.so.5
#10 0x00007f046bda628c in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/libQt5Core.so.5
#11 0x00007f046bdb2418 in QTimer::timeout(QTimer::QPrivateSignal) () at /usr/lib/libQt5Core.so.5
#12 0x00007f046bda6b1b in QObject::event(QEvent*) () at /usr/lib/libQt5Core.so.5
#13 0x00007f046c743e34 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#14 0x00007f046c74b671 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#15 0x00007f046bd7b8f9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#16 0x00007f046bdd0955 in QTimerInfoList::activateTimers() () at /usr/lib/libQt5Core.so.5
#17 0x00007f046bdcea9e in QEventDispatcherUNIX::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#18 0x00007f0463b72d4f in  () at /usr/lib/libQt5XcbQpa.so.5
#19 0x00007f046bd7a58c in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#20 0x00007f046bd82896 in QCoreApplication::exec() () at /usr/lib/libQt5Core.so.5
#21 0x00007f046d2feb26 in kdemain () at /usr/lib/libkdeinit5_kwin_x11.so
#22 0x00007f046d155223 in __libc_start_main () at /usr/lib/libc.so.6
#23 0x000055c8e55ae05e in _start ()
[Inferior 1 (process 28362) detached]

Possible duplicates by query: bug 383401.

Reported using DrKonqi
Comment 1 David Edmundson 2019-01-09 13:36:19 UTC
Please attach /home/beojan/.local/share/plasmashell/minimize.js
Comment 2 David Edmundson 2019-01-09 13:36:32 UTC
oh, it was inline, sorry
Comment 3 David Edmundson 2019-01-09 15:14:17 UTC
Use of a thread isn't guarded properly. 
Marking as confirmed. 

Will fix.
Comment 4 David Edmundson 2019-01-09 23:37:48 UTC
Git commit ba7aecfe53d765e0f94626ed00010a40284b99c0 by David Edmundson.
Committed on 09/01/2019 at 23:37.
Pushed by davidedmundson into branch 'master'.

[scripting] Avoid threading issues when loading from a file

Summary:
KWin::Script::loadScriptFromFile ran in it's own thread and accessed
member variables of KWin::Script without any guards.

Potentially script could be destroyed whilst the file is loading.

Rather than adding mutexes everywhere, this patch scopes the QFile
object to be local to the threaded function making it independent.

Test Plan: Ran a script from a file

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18126

M  +8    -8    scripting/scripting.cpp
M  +3    -6    scripting/scripting.h

https://commits.kde.org/kwin/ba7aecfe53d765e0f94626ed00010a40284b99c0
Comment 5 David Edmundson 2019-02-22 14:54:32 UTC
Git commit 47be4be0209fd786b19c5066b96c8550a08c8746 by David Edmundson.
Committed on 22/02/2019 at 14:40.
Pushed by davidedmundson into branch 'master'.

[scripting] Make DBus invokable run method return result after execution

Summary:
In 403038 the user expected the DBus call to run to finish before
processing the next request. For a singleshot script that makes a lot of
sense, otherwise you have no idea when it finishes.

This also allows us to return errors.

Test Plan:
NUM=$(qdbus org.kde.KWin /Scripting org.kde.kwin.Scripting.loadScript /noFile.js Minimize)
qdbus org.kde.KWin /$NUM org.kde.kwin.Scripting.run
  Error: org.kde.kwin.Scripting.FileError
  Could not open /noFile.js

Running a real script behaved effectively the same as before.

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18127

M  +1    -0    autotests/CMakeLists.txt
M  +2    -0    autotests/tabbox/CMakeLists.txt
M  +20   -0    scripting/scripting.cpp
M  +5    -1    scripting/scripting.h

https://commits.kde.org/kwin/47be4be0209fd786b19c5066b96c8550a08c8746