From 3b8db557eaf0d02b53620eb3f774ccfb421dcd63 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 3 Mar 2021 11:20:55 +0200 Subject: [PATCH] Don't crash during a slow (>= 60 seconds) startup on X11 The corresponding upstream bug - QTBUG-58709 - was reported in 2017 and was de-prioritized from P2 to P3 in 2020. A quick benchmark shows that the added QCoreApplication::processEvents() call takes the same time in Debug and Release builds of YACReader and YACReaderLibrary - from 0.5 to 0.6 milliseconds. 0.6 milliseconds is not a noticeable startup slowdown, especially considering that the event loop does useful work: processes events, which would have to be handled eventually anyway. Don't restrict the workaround to Linux/X11 or Debug mode: no need to introduce a potential behavior difference between supported platforms or build types. The same workaround can be applied to YACReaderLibraryServer, but I don't use the server and cannot test it. --- YACReader/main.cpp | 6 ++++++ YACReaderLibrary/main.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/YACReader/main.cpp b/YACReader/main.cpp index 90a79e18c..6daeee7ac 100644 --- a/YACReader/main.cpp +++ b/YACReader/main.cpp @@ -98,6 +98,12 @@ int main(int argc, char *argv[]) #else QApplication app(argc, argv); #endif + // Prevent SIGPIPE, then "ICE default IO error handler doing an exit(), pid = , errno = 32" + // crash on X11 when the first event loop starts at least 60 seconds after a Qt application + // launch. This can happen during a Debug launch of YACReader from Qt Creator if Qt debug + // symbols are installed in the system or a breakpoint is hit before any event loop is entered. + // This is a workaround for QTBUG-58709. + QCoreApplication::processEvents(); #ifdef FORCE_ANGLE app.setAttribute(Qt::AA_UseOpenGLES); diff --git a/YACReaderLibrary/main.cpp b/YACReaderLibrary/main.cpp index a0c06e613..9d609e6af 100644 --- a/YACReaderLibrary/main.cpp +++ b/YACReaderLibrary/main.cpp @@ -120,6 +120,11 @@ int main(int argc, char **argv) { qInstallMessageHandler(messageHandler); QApplication app(argc, argv); + // Prevent SIGPIPE, then "ICE default IO error handler doing an exit(), pid = , errno = 32" + // crash on X11 when the first event loop starts at least 60 seconds after a Qt application + // launch. This can happen during a Debug launch of YACReaderLibrary from Qt Creator if a + // breakpoint is hit before any event loop is entered. This is a workaround for QTBUG-58709. + QCoreApplication::processEvents(); #ifdef FORCE_ANGLE app.setAttribute(Qt::AA_UseOpenGLES);