Project

General

Profile

Actions

Support #11189

closed

WebSocket Message Rejection

Added by Aaron Wright over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
12/27/2022
Due date:
% Done:

0%

Estimated time:

Description

I was trying to display some large text files in a Wt::WTextArea in a Wt::WMenu. After the size of the files exceeds the --max-memory-request-size size (128 KiB), I start to get errors in the log and the site doesn't always function correctly:

[2022-Dec-27 21:10:08.732] 25657 - [error] "wthttp: Rejecting WebSocket message because it exceeds --max-memory-request-size (= 131072 bytes)"

This log message doesn't occur when clicking on the menu item for a large file, but rather, when clicking off of it to a different menu item. The large file loads up and displays fine. I don't feel like adjusting the --max-memory-request-size command line argument is right approach because the documentation says that, "Bigger POSTs are handled using a spool file." In addition, I don't even know what the large websocket message is. It seems odd that hiding a large Wt::WTextArea in a Wt::WStackedWidget would require a large websocket message. I haven't looked into the Wt code to figure out what is going on yet though.

I'm hoping this is an easily fixable bug, or that there is a workaround that I can use. Maybe I am supposed to use a very large --max-memory-request-size?

For reference, here is a sample program that demonstrations the issue:

#include "Wt/WApplication.h"
#include "Wt/WContainerWidget.h"
#include "Wt/WMenu.h"
#include "Wt/WServer.h"
#include "Wt/WStackedWidget.h"
#include "Wt/WTextArea.h"

#include <memory>
#include <string>

////////////////////////////////////////////////////////////////////////////////
class Application final : public Wt::WApplication {
public:
  explicit Application(Wt::WEnvironment const& env) : Wt::WApplication{env}
  {
    auto contents = std::make_unique<Wt::WStackedWidget>();
    auto* menu = root()->addWidget(std::make_unique<Wt::WMenu>(contents.get()));

    menu->addItem("As",
                  std::make_unique<Wt::WTextArea>(std::string(65536, 'a')));

    menu->addItem("Bs",
                  std::make_unique<Wt::WTextArea>(std::string(131072, 'b')));

    menu->addItem("Cs",
                  std::make_unique<Wt::WTextArea>(std::string(262144, 'c')));

    root()->addWidget(std::move(contents));
  }
};

////////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
  try {
    Wt::WServer server{argc, argv};

    server.addEntryPoint(
      Wt::EntryPointType::Application,
      [](auto const& env) { return std::make_unique<Application>(env); },
      "/");

    server.run();
  } catch (std::exception& ex) {
    std::cerr << ex.what() << std::endl;
    return EXIT_FAILURE;
  } catch (...) {
    std::cerr << "unknown exception" << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

To reproduce the issue, click on "Bs", and then click on "As". The error message will then be logged.

127.0.0.1 - - [2022-Dec-27 21:24:50.380] "GET /?wtd=IlWXiLSwhtKlyit5&sid=1486711372&scrW=1920&scrH=1200&tz=-480&tzS=America%2FLos_Angeles&htmlHistory=true&deployPath=%2F&request=script&rand=3111065106 HTTP/1.1" 200 18785
[2022-Dec-27 21:24:50.380] 30037 - [info] "WebRequest: took 4.835 ms"
127.0.0.1 - - [2022-Dec-27 21:24:50.386] "GET /resources/webkit-transitions.css HTTP/1.1" 200 6814
127.0.0.1 - - [2022-Dec-27 21:24:50.387] "GET /resources/themes/default/wt.css HTTP/1.1" 200 20265
127.0.0.1 - - [2022-Dec-27 21:24:50.597] "POST /?wtd=IlWXiLSwhtKlyit5 HTTP/1.1" 200 48
[2022-Dec-27 21:24:50.597] 30037 - [info] "WebRequest: took 1.148 ms"
127.0.0.1 - - [2022-Dec-27 21:24:50.599] "GET /favicon.ico HTTP/1.1" 404 85
[2022-Dec-27 21:24:51.020] 30037 - [info] "wthttp: ws: connect with protocol version 13"
[2022-Dec-27 21:24:51.026] 30037 [/ IlWXiLSwhtKlyit5] [info] "WebRequest: took 0.093 ms"
[2022-Dec-27 21:24:58.329] 30037 [/ IlWXiLSwhtKlyit5] [info] "WebRequest: took 2.815 ms"
[2022-Dec-27 21:24:58.329] 30037 [/ IlWXiLSwhtKlyit5] [info] "WebRequest: took 3.551 ms"
[2022-Dec-27 21:25:01.817] 30037 - [error] "wthttp: Rejecting WebSocket message because it exceeds --max-memory-request-size (= 131072 bytes)"
[2022-Dec-27 21:25:01.817] 30037 - [info] "WebRequest: took 10796.8 ms"
[2022-Dec-27 21:25:03.811] 30037 - [info] "wthttp: ws: connect with protocol version 13"
127.0.0.1 - - [2022-Dec-27 21:25:03.874] "POST /?wtd=IlWXiLSwhtKlyit5 HTTP/1.1" 200 48
[2022-Dec-27 21:25:03.874] 30037 - [info] "WebRequest: took 0.253 ms"

I'm currently using version 4.6.1, but I also reproduced the issue on master (4.9.0-ish).

Actions #1

Updated by Roel Standaert over 1 year ago

wthttp doesn't spool WebSocket messages, only regular requests. What's happening here is that Wt always sends the current value of all form widgets very signal, thus exceeding --max-memory-request-size.

Is there a reasonable upper limit to how large those files will be? If so, you could still simply increase the limit.

Do you need to be able to edit all of these files in the browser? If you just want to display them, then a WText would not cause the current value to be sent to the server.

If we address issue #7986 that could also alleviate this problem.

Actions #2

Updated by Aaron Wright over 1 year ago

Roel Standaert wrote in #note-1:

Do you need to be able to edit all of these files in the browser? If you just want to display them, then a WText would not cause the current value to be sent to the server.

Ah, that makes sense. I went with the Wt::WTextArea simply because I liked the way it looked, but it's read-only so I could take some time and style the Wt::WText widget the way I want it.

Thanks for help.

(If you want, you can change this from a bug to a question.)

Actions #3

Updated by Roel Standaert over 1 year ago

  • Tracker changed from Bug to Support
  • Status changed from New to Closed
Actions

Also available in: Atom PDF