Bug 382568 - Krita with Qt 5.9.1 on Windows randomly fails to send data to gmic-qt
Summary: Krita with Qt 5.9.1 on Windows randomly fails to send data to gmic-qt
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: G'Mic for Krita (show other bugs)
Version: git master (please specify the git hash!)
Platform: Microsoft Windows Microsoft Windows
: NOR major
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-21 14:17 UTC by Alvin Wong
Modified: 2017-07-30 11:05 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
DebugView output (6.88 KB, text/plain)
2017-07-21 14:17 UTC, Alvin Wong
Details
Test program for testing QLocalSocket communication (4.66 KB, text/plain)
2017-07-29 09:31 UTC, Alvin Wong
Details
Test program for testing QLocalSocket communication (qmake file) (169 bytes, text/plain)
2017-07-29 09:31 UTC, Alvin Wong
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alvin Wong 2017-07-21 14:17:05 UTC
Created attachment 106781 [details]
DebugView output

Krita:

Thread 1:
1   ntdll!ZwDelayExecution                                                                  0x779ec07a    
2   SleepEx                                                                                 0x7fefd9e1203 
3   QWindowsPipeReader::waitForPipeClosed               qwindowspipereader.cpp         356  0x7feacf4b93f 
4   QLocalSocket::waitForDisconnected                   qlocalsocket_win.cpp           408  0x7fe6cb5b285 
5   QMic::connected                                     QMic.cpp                       297  0x7fe269688b8 
... <More>                                                                                                

gmic-krita-qt-2.0.3_pre-win64 (no debug symbols):

Thread 1:
1   ntdll!ZwDelayExecution                                                                                                                                        0x779ec07a    
2   SleepEx                                                                                                                                                       0x7fefd9e1203 
3   QWindowsPipeReader::waitForNotification(int)                                                                                                                  0x66892356    
4   QWindowsPipeReader::waitForReadyRead(int)                                                                                                                     0x66892435    
5   QLocalSocket::waitForReadyRead(int)                                                                                                                           0x6d2adaf3    
6   ??                                                                                                                                                            0x40988c      
7   ??                                                                                                                                                            0x40b55d      
8   ??                                                                                                                                                            0x478e86      
9   ??                                                                                                                                                            0x47e321      
10  QWidget::event(QEvent *)                                                                                                                                      0x17bcff8     
11  QApplicationPrivate::notify_helper(QObject *, QEvent *)                                                                                                       0x1777f9c     
12  QApplication::notify(QObject *, QEvent *)                                                                                                                     0x177eefc     
13  QCoreApplication::notifyInternal2(QObject *, QEvent *)                                                                                                        0x668cb812    
14  QWidgetPrivate::sendPaintEvent(QRegion const&)                                                                                                                0x17b561d     
... <More>                                                                                                                                                                      

Judging from the time it takes to call `QLocalSocket::waitForReadyRead` (1 second), the deadlock probably happens here (unless the code has changed after the release): https://github.com/c-koi/gmic-qt/blob/8e4511256c0b420f33252356d4741034044423ae/src/host_krita.cpp#L92

Attached the DebugView output.

"QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState	" appears rather frequently, it might be related.
Comment 1 Alvin Wong 2017-07-21 14:33:43 UTC
An additional note, my Krita is compiled with Qt 5.9.1
Comment 2 Alvin Wong 2017-07-21 16:34:54 UTC
Git commit eaa459e3c28951ef3b280271d8f370a848f92e16 by Alvin Wong.
Committed on 21/07/2017 at 16:17.
Pushed by alvinwong into branch 'krita/3.2'.

Do not wait indefinitely for socket in QMic plugin

This works around a possible lockups with gmic-qt. Instead of waiting
for the socket forever, it should only freeze for a aximum of 8
seconds.

M  +14   -5    plugins/extensions/qmic/QMic.cpp

https://commits.kde.org/krita/eaa459e3c28951ef3b280271d8f370a848f92e16
Comment 3 Alvin Wong 2017-07-21 16:35:07 UTC
Git commit 2c9c9cb2709f700d195bd0cfffd939f4a61b69e0 by Alvin Wong.
Committed on 21/07/2017 at 16:16.
Pushed by alvinwong into branch 'master'.

Do not wait indefinitely for socket in QMic plugin

This works around a possible lockups with gmic-qt. Instead of waiting
for the socket forever, it should only freeze for a aximum of 8
seconds.

M  +12   -3    plugins/extensions/qmic/QMic.cpp

https://commits.kde.org/krita/2c9c9cb2709f700d195bd0cfffd939f4a61b69e0
Comment 4 Alvin Wong 2017-07-21 16:38:02 UTC
I made some changes to stop the lockups, but it just hides the actual bug, gmic-qt will sometimes not able to receive the image data properly and cause other errors.
Comment 5 Alvin Wong 2017-07-22 14:41:55 UTC
This will appear in DebugView occasionally and gmic-qt will show some error or an empty image (PID 8608 is gmic-qt).

[11308] Sending "key_{bb238f3f-6f95-4a63-ae5b-5c5e60fb4c0c},4c61796572203136,3600,2400\n"
[11308] Failed to write response: QLocalSocket::UnknownSocketError
[11308] Remote not disconnected: QLocalSocket::UnknownSocketError
[11308] QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState
[8608] Stale request
[8608]  gmic-qt: empty answer!
[8608] QImage::scaled: Image is a null image

Look for "Failed to write response" and "Stale request".

I was not able to reproduce this at all with 3.2.0 beta 2 (which uses Qt 5.6.1).
Comment 6 Alvin Wong 2017-07-29 09:31:23 UTC
Created attachment 106940 [details]
Test program for testing QLocalSocket communication
Comment 7 Alvin Wong 2017-07-29 09:31:51 UTC
Created attachment 106941 [details]
Test program for testing QLocalSocket communication (qmake file)
Comment 8 Alvin Wong 2017-07-29 09:34:59 UTC Comment hidden (obsolete)
Comment 9 Alvin Wong 2017-07-30 09:44:44 UTC Comment hidden (obsolete)
Comment 10 Alvin Wong 2017-07-30 10:49:44 UTC
Git commit a0eef62be22fe6e30293a840fd3cb580fe79772f by Alvin Wong.
Committed on 30/07/2017 at 10:49.
Pushed by alvinwong into branch 'master'.

Work around possible gmic-qt write issues with Qt 5.7+

M  +5    -0    plugins/extensions/qmic/QMic.cpp

https://commits.kde.org/krita/a0eef62be22fe6e30293a840fd3cb580fe79772f
Comment 11 Alvin Wong 2017-07-30 11:05:29 UTC
Worked around, so I'll call this fixed. Delaying the real "fix" until someone decide to improve on the IPC code in the Qmic plugin...