Several months ago I upgraded to naviserver-4.99.23rc1 and
initially everything seemed fine, but at some point I noticed
that if naviserver was restarted the bind port was already taken.

I was using daemontools supervise/svc (started with systemd) to
start/stop/restart. Initially I blamed systemd since the additional
process could be controlled with systemctl. 

This system is Fedora 32 x64 (DigitalOcean droplet), but I have just
verified that the bug shows up on Ubuntu as well.

I used git bisect to locate the exact commit which created the bug,
here's the patch (but see links below):

--- binder.c    2021-08-16 11:59:07.000000000 +0000
+++ binder.c    2021-12-11 06:24:52.543180128 +0000
@@ -1307,12 +1307,10 @@
             (void)ns_sockclose(binderRequest[1]);
             (void)ns_sockclose(binderResponse[0]);
             Binder();
-        } else {
-            /*
-             * Child process.
-             */
-            exit(0);
         }
+
+        exit(0);
+
     } else {
         /*
          * Parent process.

-------------
I believe that the exit(0), placed inside the trailing else allowed
the Binder() to survive. 

Here are my notes (from tags-commits.txt below):
[russell@highfivediet naviserver]$ git bisect --help
[russell@highfivediet naviserver]$ git bisect start
[russell@highfivediet naviserver]$ git bisect bad
[russell@highfivediet naviserver]$ git bisect good naviserver-4.99.17

Bisecting: 698 revisions left to test after this (roughly 10 steps)
STEP1: [65689e7c2cfee84bcf4a9789b4ff14f500e57861] make sure, variable is always 
initialized
STEP2: [ffeafdebecb999732712c6edf891917ea0eeab4d] Use "for(;;)" instead of 
"while(1)" like on other places
STEP3: [010daa96412eaf7f02833aa7a9c255ad09b68d8d] fix default temp directory 
for windows
STEP4: [9a445fcf1b15490728d5803ba3d21df7024eb4c1] Improved compilation 
cleanness with gcc-11
STEP5: [7909e79e8d41a12dd35e9b28c1afe7dcce9627b0] improved spelling and aligned 
documentation with code
STEP6: [b70152a504024c4ccf283c2ced9ea6a2a7698511] Fixed Apple M1 problem with 
double-fork in NsBinder()
STEP7: [51c21ec5bcc4c9c06c6fd1b51b8c27abe5d07bd6] improve variable name ( 
NaviServer/4.99.22rc1 (naviserver-4.99.20-155-g51c21ec5bcc4+) ) <== BAD
STEP8: [db057401dae34267279f16299b1aee7570240341] styling conventions: use 
uppercase for hexdigits (NaviServer/4.99.21 
(naviserver-4.99.20-149-gdb057401dae3+) ) <== GOOD
STEP9: [7bf2468775ccbbf2191db7b5382624b173332121] fix man page ( 
NaviServer/4.99.21 (naviserver-4.99.20-152-g7bf2468775cc+) ) <== BAD 
STEP10:[f7740ac62376d99170f904403a9bc50d80824b44] minor cleanup ( 
NaviServer/4.99.21 (naviserver-4.99.20-151-gf7740ac62376+) ) <== BAD
Bisecting: 0 revisions left to test after this (roughly 0 steps)
STEP11:[8114f6870009985366a65342928062f08cde80fe] Added more comments to 
double-fork construct in NsForkBinder() ( NaviServer/4.99.21 
(naviserver-4.99.20-150-g8114f6870009+) ) <== BAD 

[russell@highfivediet naviserver]$ git bisect bad
8114f6870009985366a65342928062f08cde80fe is the first bad commit
commit 8114f6870009985366a65342928062f08cde80fe
Author: Gustaf Neumann <neum...@wu-wien.ac.at>
Date:   Mon Aug 16 13:58:04 2021 +0200

    Added more comments to double-fork construct in NsForkBinder()

 nsd/binder.c | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

----- MORE INFO -----

More info generated by git is here: 

https://highfivediet.com/bugs/binder-bug/

The bug doesn't show up in every case, obviously you have to use
the binder switch, but even using a simple command line startup 
didn't create an issue. I have include my startup script at

https://highfivediet.com/bugs/binder-bug/run.txt

Easiest way to test for the bug is to startup and then use
$ ps -axjf and looking for an additional process (same PPID).

On Fedora, this process was connected to pid 1, but on Ubuntu it
was connected to the gnome-terminal-server process.

Otherwise if you kill either of these and then run 
$ ss -ltnp   
the duplicate process is still running on the port (and works fine).

Let me know if more information is needed or if you need other test
run.

Russ



_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to