Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a potential log spamming and DOS attack #308

Merged
merged 2 commits into from Sep 5, 2022
Merged

Fix a potential log spamming and DOS attack #308

merged 2 commits into from Sep 5, 2022

Conversation

kulkom
Copy link
Contributor

@kulkom kulkom commented Aug 29, 2022

What does this do and why is this needed?

I have discovered an attack that allows you to attack any non-trivial programs that use onion. At the very least it allows you to spam the logs with a few hundred thousand useless messages, and maybe even deny service to other clients. And the worst part about it? You only need Firefox (maybe Chrome can do it as well, I haven't tested that) and a functional F5 key.

To reproduce it:

  1. Download, compile and run the source file below, it's a program that simulates a non-trivial onion app by writing 200000-something chars when requested at <Your IP>:8080/teapot.
  2. Download Mozilla's finest web browser if you don't have it already.
  3. Open up Firefox and browse to localhost:8080/teapot.
  4. Make sure the Firefox window is in focus and hold down the F5 key for a few minutes.
  5. That's it. Now the logs are full of pointless messages and for me the program stopped responding for ~30 seconds.
C source file
#include <stdlib.h>

#include "onion/src/onion/onion.h"
#include "onion/src/onion/response.h"

static onion_connection_status be_a_teapot (void * _, onion_request * req, onion_response * rsp)
{
  (void) _; (void) req;
  onion_response_set_code (rsp, 418);

  onion_response_printf (rsp, "%s", "<!DOCTYPE html><h1 style=\"display: inline;\">418.</h1><h2 style=\"display: inline;\">I'm a teapot.</h2><hr><p>The resulting entity body is<strong> NOT</strong> short and stout.<br>Tip me over and pour me out<strong> AND ENJOY THE USELESS INVISIBLE A's BELOW</strong>.</p><p style=\"display: none;\">");
  for (unsigned int i = 0; i < 200000; ++i)
    onion_response_printf (rsp, "%c", 'A');
  onion_response_printf (rsp, "%s", "</p>");

  return OCS_PROCESSED;
}

int main ()
{
  onion * webserver = onion_new (O_THREADED);
  onion_url * webserver_urls = onion_root_url (webserver);

  onion_url_add (webserver_urls, "teapot", be_a_teapot);

  onion_set_hostname (webserver, "0.0.0.0");

  onion_listen (webserver);
  onion_free (webserver);

  return EXIT_SUCCESS;
}

So, how does it work?

It's quite simple: when Firefox refreshes, it'll reset all current connections with the server, if any, and then it'll reconnect. Thus, by holding down F5 Firefox will connect to the server and reset that connection almost immediately and will continue doing that while the key is being held down. When the connection is reset, onion will complain about being unable to write the chunk encoding length in a warning, which is reasonable behavior most of the time - but not always. By connecting and resetting countless times we'll not only create a bunch of useless warnings in the log, but we'll also make all the threads very busy writing that log down to the stdout (or syslog). And, quite obviously, when a thread is writing a warning to the log it's not doing any serving, and when all threads are writing to the log the client will not get served at all.

The fix

The fix is as simple as the problem: allow onion to log a chunk encoding write error only once a second, and at other times just count the errors and output the count if an error occurs after a second since the previous warning had been written.

Logs of the sample program before the commit

Some onion logs
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A14E5640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9F4E1640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[9FCE2640] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.
[A24E8740] [2022-08-30 02:46:51] [WARNING response.c:436] Error writing chunk encoding length (5DC) Broken pipe. Aborting write.

Logs of the sample program after the commit

Some more onion logs
[76D4D640] [2022-08-30 02:37:25] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 200298 (Keep-Alive)
[76D4D640] [2022-08-30 02:37:25] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 200298 (Keep-Alive)
[76D4D640] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x1)
[7754E640] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Connection reset by peer. Aborting write. (x1)
[79D54740] [2022-08-30 02:37:26] [ERROR response.c:470] Error writing 1500 bytes (Broken pipe). Maybe closed connection. Code -1. 
[79D54740] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x1)
[77D4F640] [2022-08-30 02:37:26] [ERROR response.c:470] Error writing 1500 bytes (Broken pipe). Maybe closed connection. Code -1. 
[77D4F640] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x1)
[78550640] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x1)
[78D51640] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x1)
[79552640] [2022-08-30 02:37:26] [ERROR response.c:470] Error writing 1500 bytes (Broken pipe). Maybe closed connection. Code -1. 
[79552640] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x1)
[77D4F640] [2022-08-30 02:37:26] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 120564000 (Keep-Alive)
[79D53640] [2022-08-30 02:37:26] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x1)
[77D4F640] [2022-08-30 02:37:26] [ERROR response.c:470] Error writing 1500 bytes (Broken pipe). Maybe closed connection. Code -1. 
[76D4D640] [2022-08-30 02:37:26] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 255475500 (Keep-Alive)
[7754E640] [2022-08-30 02:37:26] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 289203000 (Keep-Alive)
[7754E640] [2022-08-30 02:37:26] [ERROR response.c:470] Error writing 1500 bytes (Broken pipe). Maybe closed connection. Code -1. 
[79552640] [2022-08-30 02:37:26] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 221746500 (Keep-Alive)
[79D54740] [2022-08-30 02:37:26] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 120564000 (Keep-Alive)
[76D4D640] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x290018)
[79552640] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x228379)
[77D4F640] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x110453)
[78D51640] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x65054)
[79D53640] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x49581)
[78550640] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x81892)
[79D54740] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x81263)
[7754E640] [2022-08-30 02:37:27] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x230463)
[76D4D640] [2022-08-30 02:37:27] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[79552640] [2022-08-30 02:37:27] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[76D4D640] [2022-08-30 02:37:27] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[79552640] [2022-08-30 02:37:27] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[79552640] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x444114)
[78550640] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x53793)
[76D4D640] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x396747)
[78D51640] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x59457)
[79D53640] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x58540)
[79D54740] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x55083)
[77D4F640] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x62441)
[7754E640] [2022-08-30 02:37:28] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x57029)
[79552640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[76D4D640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[79D53640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[78D51640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[78550640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[77D4F640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 291450000 (Keep-Alive)
[7754E640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 286953000 (Keep-Alive)
[79D54740] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[79552640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[7754E640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 200298 (Keep-Alive)
[76D4D640] [2022-08-30 02:37:28] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[78550640] [2022-08-30 02:37:29] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x147911)
[79D53640] [2022-08-30 02:37:29] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x184922)
[78D51640] [2022-08-30 02:37:29] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x176673)
[77D4F640] [2022-08-30 02:37:29] [WARNING response.c:453] Error writing chunk encoding length (5DC) Broken pipe. Aborting write. (x208733)
[77D4F640] [2022-08-30 02:37:29] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[79D53640] [2022-08-30 02:37:29] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[78550640] [2022-08-30 02:37:29] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)
[78D51640] [2022-08-30 02:37:29] [INFO response.c:196] [127.0.0.1] "GET /teapot" 418 298197000 (Keep-Alive)

@kulkom
Copy link
Contributor Author

kulkom commented Aug 31, 2022

Hi @davidmoreno , is there anything wrong with this commit that you don't want to merge it?
Please let me know if that's the case, thanks.

@davidmoreno
Copy link
Owner

Hi,

first of all thanks for the full report, very detailed. Appreciated.

I have had not much time for reviewing, but some details:

  • I dont like so many defines in the middle of the code, makes it very difficult to read. If the problem is that there are several types depending on the OS, and/or different functions to call, the place is at onion_low.h. Create a new type there and that's the one to be used through the application, without the need of ifdefs.
  • Also somehow i think it should be possible to encapsulate this logic of show only once every X seconds max in a nice function or macro (somehow I think macro to be able to use a static variable the same way you used it. So at place of use it would be quite high level with a CALL_MAX_ONCE_PER_T(1, ONION_WARNING(...)) or ONION_WARNING_MAX_PER_T(1, ...) or similar, where the first one is the max seconds between calls, and the rest a normal ONION_WARNING call. Name totally subject to better suggestions.

Both ideas are in the same line of making the code at the place of use very concise and easy to read. And create infrastructure so it can be reused.

Regards,
David.

@kulkom
Copy link
Contributor Author

kulkom commented Sep 1, 2022

Roger! To be honest I really should have thought better especially about the huge define section, I simply googled "c cross platform thread local" lol. Will fix both points once I have free time.

Thanks for the quick reply.

@kulkom
Copy link
Contributor Author

kulkom commented Sep 5, 2022

@davidmoreno Is it good enough now?

@davidmoreno davidmoreno merged commit de8ea93 into davidmoreno:master Sep 5, 2022
@davidmoreno
Copy link
Owner

Very good indeed! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants