Project

General

Profile

Bug #7440

WTimer results in excessive browser CPU and memory usage when connection is lost

Added by Christopher Bilberg over 2 years ago. Updated over 2 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
02/04/2020
Due date:
% Done:

0%

Estimated time:

Description

We are using a WTimer to trigger updates in our application, however when the connection to the server is lost the WTimer triggers the CPU and memory to explode.

If I run the following code:

#include <Wt/WApplication>
#include <Wt/WTimer>
#include <Wt/WText>

class TimerApplication : public Wt::WApplication
{
public:
    TimerApplication(const Wt::WEnvironment& env) : Wt::WApplication(env) {
      Wt::WText* text = new Wt::WText(root());
      Wt::WTimer* timer = new Wt::WTimer(this);
      timer->setInterval(10);
      timer->timeout().connect(std::bind([ = ]() {
        text->setText("Count is " + std::to_string(count++));
      }));
    timer->start();
    }
private:
  int count = 0;
};

Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
    return new TimerApplication(env);
}

int main(int argc, char **argv)
{
    return Wt::WRun(argc, argv, &createApplication);
}

The browser will for instance use around 20 % CPU when there is connection to the server, however as soon as the connection is lost, this goes up to 60-80 % and keeps increasing together with the memory usage. Eventually this will cause the whole browser to become unresponsive. The browser itself keeps printing net::ERR_CONNECTION_REFUSED errors, which makes sense, however I don't see why this basically has to make the entire browser freeze.

We are running Wt 3.4.1 and I used Google Chrome 79 for testing.

Is there a way to get around this? As for instance stop sending requests after it has been refused a certain number of times.

Also available in: Atom PDF