Hi Lucas, William,
I've made a patch which 'i think' fixes the issue with fclose called 'to
often?'.
Can you guys verify?
I hope it helps.. but then again, maybe not the right way .?.
(I really have to little experience with these kind of things..)
Op 25-12-2017 om 10:25 schreef Willy Tarreau:
On Sun, Dec 24, 2017 at 07:36:54PM +0100, Willy Tarreau wrote:
The bug has been introduced in commit baf6ea4b (" BUG/MINOR: mworker:
detach from tty when in daemon mode") and affects 1.8.1 and newer
stable releases.
The discourse-OP also states that the socket is likely closed by the
triple flcose() introduced in that bisected commit.
Ah bad :-( But interestingly, we were speaking about using CLOEXEC on
listeners, I think this will make all of this much easier to deal with.
I guess we
first want to clearly describe how we want each process to behave in
each case (mw+debug, mw+quiet, mw+daemon, debug, quiet, daemon). This
way we'll avoid pushing fixes which break other use cases ;-)
Regards,
Willy
And then below some 'ramblings' that also might not all make sense... :)
I've made the assumption that when running in daemon mode there should
never be any output to the stdin/out/err files when the masterworker is
re-executing itself, and those 'files' are already closed as the master
process doesn't really change.. or does it.?.
Is this correct, or would it just introduce another bug.?. I'm not
really sure how to properly check for used the fd's in child processes
and what they are used for...
As for writing out what is expected for each case. I think this would be
it, including current results..:
The short version would be like this:
<normal> - warnings+errors
debug - pollerinfo+warnings+errors+connections
quiet - no output except errors
daemon - no output after first startup
master-worker - the same information as 'normal'? (also after a
reload, including connections info??)
Below are the above options in various combinations and if they produce
expected result..
mw:
warning+error (OK)
after reload:
warning+error (OK)
mw+quiet(in config):
only shows FIRST-startup errors (OK i guess, or should stdout not
be closed as another re-start could be done and would desire error to be
shown again..?.)
after reload:
<no output> (OK) (or should it 'keep open' the stdout so it can
output config errors again ?)
after reload without quiet config option:
<EXIT> (FAIL?)
mw+debug:
polling info+warning+error (currently doesn't show
debugging/headers info of connections).. (FAIL or intentional?)
after reload:
polling info+warning+error (currently doesn't show
debugging/headers info of connections) (?)
mw+daemon:
shows first startup errors+warnings(OK)
after reload:
<no output> (OK)
mw+daemon+quiet:
shows first startup errors (OK)
after reload:
<no output> (OK)
mw+daemon+debug:
shows first warnings+errors (OK)
after reload:
<no output> (OK)
debug:
shows pollerinfo+error+warning+debugging/headers (OK)
quiet:
shows startup errors (OK)
daemon:
shows startup warnings+errors (OK)
daemon+debug:
shows startup warnings+errors (OK)
daemon+quiet: shows first startup errors (OK)
shows startup errors (OK)
So removing 'quiet' from the config does something unwanted for MW.
And another possible issue i found is that when MW is reloaded with USR2
and the config contains a error, after that is corrected and another
SIG2 is send then the -x is not used when launching the new worker..
Seems to work OK afterwards though.. Is this intentional.?
Anyhow, wish you all good Christmas day(s) and a happy new year.
Regards,
PiBa-NL / Pieter
From 49272b2c0bafb413f0fb89717f17c784c2947a4f Mon Sep 17 00:00:00 2001
From: PiBa-NL <pba_...@yahoo.com>
Date: Mon, 25 Dec 2017 21:03:31 +0100
Subject: [PATCH] BUG/MEDIUM: mworker: avoid closing stdin/stdout/stderr file
descriptors multiple times in the same master process
This makes sure that a frontend socket that gets created after initialization
wont be closed when the mworker gets re-executed.
---
src/haproxy.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/haproxy.c b/src/haproxy.c
index ffd7ea0..0666ad0 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2579,10 +2579,19 @@ int main(int argc, char **argv)
signal_register_fct(SIGTTIN, sig_listen, SIGTTIN);
/* MODE_QUIET can inhibit alerts and warnings below this line */
-
- if ((global.mode & MODE_QUIET) && !(global.mode & MODE_VERBOSE)) {
- /* detach from the tty */
- fclose(stdin); fclose(stdout); fclose(stderr);
+
+ if (getenv("HAPROXY_MWORKER_REEXEC") != NULL) {
+ // either stdin/out/err are already closed or should stay as
they are.
+ if ((global.mode & MODE_DAEMON)) {
+ // daemon mode re-executing, stdin/stdout/stderr are
already closed so keep quiet
+ global.mode &= ~MODE_VERBOSE;
+ global.mode |= MODE_QUIET; /* ensure that we won't say
anything from now */
+ }
+ } else {
+ if ((global.mode & MODE_QUIET) && !(global.mode &
MODE_VERBOSE)) {
+ /* detach from the tty */
+ fclose(stdin); fclose(stdout); fclose(stderr);
+ }
}
/* open log & pid files before the chroot */
--
2.10.1.windows.1