Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Sending message can occasionally max out CPU thread #5620

Open
sterro opened this issue Apr 14, 2019 · 9 comments
Open

Sending message can occasionally max out CPU thread #5620

sterro opened this issue Apr 14, 2019 · 9 comments
Labels
C-bug The issue contains a bug report
Milestone

Comments

@sterro
Copy link

sterro commented Apr 14, 2019

Brief Description

OS: Linux x64, Fedora 29 and 30 beta
qTox version: v1.16.3-384-gdf62463e, newest version from a few days ago
toxcore: 0.2.9
Qt: 5.11.3

Reproducible: happens to me multiple times a day with different people, but rarely and not every time a message is sent

Steps to reproduce
  1. Send a message to someone
  2. Sometimes it will appear to use 100% CPU usage for a thread I think (so my Linux reports 25% CPU for the qTox binary)
  3. Restarting qTox or sending a different message fixes it
Observed Behavior

Here is a video I took when I got it to happen recently, I sent a message to my online friend which caused the CPU Usage to spike permanently, if you hover over it the mouse cursor gets all glitchy over the link (although I’ve had this happen on non link messages as well)

https://gfycat.com/MeagerIllinformedGrasshopper

I sent another message and the problem goes away, but I’m pretty sure it’s also happened when I’ve been sent a message by a different friend since I’ve seen the same problem when unlocking my computer in the morning where it was using 25% CPU for who knows how long

Let me know if there is anything I can do to help debug this. I had the same problem when testing the new Fedora 30, and there didn’t seem to be any errors or debug messages when running qTox from a terminal

@sudden6
Copy link
Member

sudden6 commented Apr 14, 2019

@anthonybilinski I think this might be the same bug I told you about

@sudden6 sudden6 added the C-bug The issue contains a bug report label Apr 14, 2019
@sudden6
Copy link
Member

sudden6 commented May 2, 2019

I got this again, this time in the following environment:

  • In a group chat with 2 other people
  • qTox was in foreground
  • I only received messages

The high CPU usage stopped when I changed the active chat and returned when I switched back to the problematic chat.

@anthonybilinski
Copy link
Member

I hit this today after sending a pending message to an offline friend. Scrolling up in the chat any amount at all fixed the problem, scrolling back down re-caused the problem. I managed to grab a backtrace of the offending thread:

Thread 1 (Thread 0x7fe40dbd7300 (LWP 5393)):
#0  0x00007fe41cb64d63 in  () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#1  0x00007fe41cb917c2 in QRasterPaintEngine::alphaPenBlt(void const*, int, int, int, int, int, int, bool) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#2  0x00007fe41cb99160 in QRasterPaintEngine::drawCachedGlyphs(int, unsigned int const*, QFixedPoint const*, QFontEngine*) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#3  0x00007fe41cb9cc67 in QRasterPaintEngine::drawTextItem(QPointF const&, QTextItem const&) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#4  0x00007fe41cbb4c2c in  () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#5  0x00007fe41ca30aa0 in QTextLine::draw(QPainter*, QPointF const&, QTextLayout::FormatRange const*) const () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#6  0x00007fe41ca31ec5 in QTextLayout::draw(QPainter*, QPointF const&, QVector<QTextLayout::FormatRange> const&, QRectF const&) const () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#7  0x00007fe41ca7316c in  () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#8  0x00007fe41ca7517a in  () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#9  0x00007fe41ca74bbe in  () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#10 0x00007fe41ca7e8bc in QTextDocumentLayout::draw(QPainter*, QAbstractTextDocumentLayout::PaintContext const&) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#11 0x000055a0fc9264a1 in Text::paint(QPainter*, QStyleOptionGraphicsItem const*, QWidget*) (this=0x55a107160a50, painter=0x7ffc3928f5b0, option=0x55a1024fadb8, widget=0x55a1024fa4c0) at /home/abilinski/builds/qTox/src/chatlog/content/text.cpp:239
#12 0x00007fe41d23c5b9 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#13 0x00007fe41d23d2a2 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#14 0x00007fe41d23d7ee in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#15 0x00007fe41d2612d6 in QGraphicsView::paintEvent(QPaintEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#16 0x00007fe41cf6eb58 in QWidget::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#17 0x00007fe41d0136ce in QFrame::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#18 0x00007fe41d25fd23 in QGraphicsView::viewportEvent(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#19 0x00007fe41c3b45fb in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#20 0x00007fe41cf2f541 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#21 0x00007fe41cf36930 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#22 0x00007fe41c3b48e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#23 0x00007fe41cf67795 in QWidgetPrivate::sendPaintEvent(QRegion const&) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#24 0x00007fe41cf68057 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#25 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#26 0x00007fe41cf68b40 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#27 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#28 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#29 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#30 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#31 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#32 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#33 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#34 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#35 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#36 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#37 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#38 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#39 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#40 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#41 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#42 0x00007fe41cf68c51 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#43 0x00007fe41cf67cdc in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#44 0x00007fe41cf3f3ac in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#45 0x00007fe41cf3f729 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#46 0x00007fe41cf57035 in QWidgetPrivate::syncBackingStore() () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#47 0x00007fe41cf6ec88 in QWidget::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#48 0x00007fe41d076cd4 in QMainWindow::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#49 0x000055a0fc8af4b4 in Widget::event(QEvent*) (this=0x55a0fe53a000, e=0x55a10242d1f0) at /home/abilinski/builds/qTox/src/widget/widget.cpp:1986
#50 0x00007fe41cf2f551 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#51 0x00007fe41cf36930 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#52 0x00007fe41c3b48e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#53 0x00007fe41c3b7927 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#54 0x00007fe41d22ffd1 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#55 0x00007fe41d2356c9 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#56 0x00007fe41c3deca2 in QObject::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#57 0x00007fe41d24193b in QGraphicsScene::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#58 0x00007fe41cf2f551 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#59 0x00007fe41cf36930 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#60 0x00007fe41c3b48e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#61 0x00007fe41c3b7927 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#62 0x00007fe41c408a43 in  () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#63 0x00007fe41deb7aae in g_main_context_dispatch () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#64 0x00007fe41deb7d48 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#65 0x00007fe41deb7ddc in g_main_context_iteration () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#66 0x00007fe41c408047 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#67 0x00007fe41c3b35bb in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#68 0x00007fe41c3bb5e2 in QCoreApplication::exec() () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#69 0x000055a0fc835f03 in main(int, char**) (argc=3, argv=0x7ffc39292738) at /home/abilinski/builds/qTox/src/main.cpp:369

Adjusting the window height also prevents and recreates the issue. It looks like if I stretch the window vertically so that there is room for the top centre date, the CPU usage drops:
image

if I then shrink the window vertically, the date dissapears, but the white bar it was on stays and hides text under it. During this range the CPU is 100%:
image

as I shrink more, the white bar dissapears, and the text that was under it is shown, and CPU drops again:
image

@anthonybilinski anthonybilinski added this to the v1.17.0 milestone Jun 11, 2019
@sudden6
Copy link
Member

sudden6 commented Aug 19, 2019

This didn't happen for me since a while, maybe it got fixed on master?

@anthonybilinski
Copy link
Member

I've seen it as recently as yesterday on tip, with the same repro steps of half-covered date line.

@ConorJS
Copy link

ConorJS commented Sep 21, 2019

This happens to me on Windows 7 Build 7601, on qTox v1.16.3-514-ge8d48e8.

Scrolling up in the chat any amount at all fixed the problem, scrolling back down re-caused the problem.

@sphaerophoria
Copy link
Contributor

I believe the cause of this bug comes from

    connect(chatWidget, &ChatLog::firstVisibleLineChanged, this, &GenericChatForm::updateShowDateInfo);
...
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)
{
    const auto date = getTime(line);

    if (date.isValid() && date.date() != QDate::currentDate()) {
        const auto dateText = QStringLiteral("<b>%1<\b>").arg(date.toString(Settings::getInstance().getDateFormat()));
        dateInfo->setText(dateText);
        dateInfo->setVisible(true);
    } else {
        dateInfo->setVisible(false);
    }
}

If the top line is not today, but the second line is, we will flicker back and forth between showing the date and not showing the date. This is because when the date is shown it covers the message of the previous date. We then say "hey the first message is today, so we can hide the date line again" which causes the first line to not be today again.

sphaerophoria added a commit to sphaerophoria/qTox that referenced this issue Oct 12, 2019
The previous implementation of hiding the date line would cause 100% cpu
usage. When the date line was shown it would hide the top line, causing
the date line to be hidden again due to a state change in which dates
was visible.

This is a minimal patch to work around the issue by pretending the line
covered by the date line is the first visible line when the dateline is
shown

Fixes qTox#5620
sphaerophoria added a commit to sphaerophoria/qTox that referenced this issue Nov 9, 2019
The previous implementation of hiding the date line would cause 100% cpu
usage. When the date line was shown it would hide the top line, causing
the date line to be hidden again due to a state change in which dates
was visible.

This is a minimal patch to work around the issue by pretending the line
covered by the date line is the first visible line when the dateline is
shown

Fixes qTox#5620
@anthonybilinski
Copy link
Member

Fixed by #5875, which was merged to branch v1.17-dev.

@sterro
Copy link
Author

sterro commented Jun 24, 2020

I've noticed this still happening on occasion for a while and can confirm it's still happening on the newest master version for me. When the date bar above the messages isn't visible the CPU maxes out and hovering over an offending message containing a link makes the cursor blink like in the original post, and when I can get the date to reappear (either by scrolling up/down or switching to a different UI tab and going back) it stops blinking and the CPU goes back to 0%.

v1.17.2-241-gdef038a8
Toxcore: 0.2.12
Qt: 5.14.2

I'm not sure what circumstances cause the date area to be blank sometimes but that's definitely the trigger for this happening. This most recent time, it happened after compiling the newest version, opening it and viewing the chat of a friend where the most recent messages were from yesterday.

Also the date not showing doesn't guarantee the CPU spike happening either, a lot of the time it works as expected and there is no issue even if the date isn't being displayed.

datebar
The date area looks like this when it happens, expanded but empty

Edit: FWIW, I haven't had this happen since posting this 17 days, so it seems like whatever causes it to still happen is a lot harder to trigger

@sudden6 sudden6 reopened this Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-bug The issue contains a bug report
Projects
None yet
Development

No branches or pull requests

5 participants