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

fgetline fgets() race handling #920

Open
wants to merge 2,087 commits into
base: master
Choose a base branch
from

Conversation

TerraTech
Copy link
Contributor

This patch is to handle a fgets() + EOF/EAGAIN race in fgetline(), as well as adding two new switches to tweak its behavior.

I stumbled on this when I changed my log feeder to do something like the following:

{ printf "<custom crafted first log line>\n"; ssh remote gunzip -c logfile; } | pv | goaccess ....

The delay would sometimes cause the fgets() to go in a read loop and never exit in the face of either an EOF or EAGAIN.

The --getline-min-read specifies the minimum number of lines that must be read before it will quickly exit the read loop on an EOF/EAGAIN. This covers the case where the logs being fed is a combination of 'fast' (printf) and 'slow' feeds where the slow feed incurs a remote ssh connection delay. This covers how EOF/EAGAIN is handled as it should honor it after log lines have been fed for it, but be very conservative and wait for the log stream to start. Non-blocking stream reads can get a bit tricky as the onus is on the coder to cover all the corner cases. (I hope that makes sense).

As a belt-n-suspenders approach, it also has a --getline-timeout which will break out of the loop after specified number of seconds. The default is 10, and has worked well for our use case.

Please give it a lookover and let me know what you think. Thanks!

allinurl and others added 30 commits April 12, 2017 20:12
lintian:
I: goaccess: spelling-error-in-binary usr/bin/goaccess occured occurred
I: goaccess: spelling-error-in-binary usr/bin/goaccess Diable Disable
Those resources are converted to C and embedded into the final binary
during the build. There is no point in also installing them to
$(PREFIX)/share/doc/goaccess/
@TerraTech
Copy link
Contributor Author

rebased to master and ready to merge

allinurl and others added 16 commits November 1, 2017 07:33
output.c: Suppress Google Chrome translation
…/EAGAIN.

  1) Add getline_{timeout,min_read} defaults to global 'conf'
  2) Fixup fgetline() nanosleep to use SLEEP macro, that can be
     overridden during compile time if needed.
…ld only be built if WITH_GETLINE is in play.

  fgetline() is only called from a wrapped
  >> #ifdef WITH_GETLINE
  >> read_lines() {
  >> ==> fgetline()
  >> }
  >> #endif
@allinurl
Copy link
Owner

Thanks. I haven't been able to merged this as I'm trying to keep up with some bugs/requests that I plan to squeeze in the next release. I still want to run some tests on my side before merging this commit.

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