Zeronet: [0.6.5 regression] Doesn't stop on SIGTERM signal

Created on 17 Feb 2019  Â·  18Comments  Â·  Source: HelloZeroNet/ZeroNet

On FreeBSD kill -SIGTERM 98008 doesn't kill the zeronet process.

Normally zeronet is run using the daemon process.
It runs under the daemon parent:

    0 root      -16   0     0  8880 S  0.0  0.0  4:55.15 kernel
    1 root       20   0  5416   188 S  0.0  0.0  0:00.08 └─ /sbin/init --
98007 root       20   0  6372  2204 S  0.0  0.0  0:00.01    ├─ daemon: /usr/local/share/zeronet/zeronet.py[98008]
98008 nobody     20   0 96956 80872 S  0.0  0.3  0:04.42    │  └─ python2.7 /usr/local/share/zeronet/zeronet.py --ui_host localhost:43110 --tor always --debug
................etc..................

To stop the child, daemon sends SIGTERM. But zeronet now doesn't stop on SIGTERM.

Ignoring SIGTERM makes zeronet not a well behaved process. Users should be able to stop it in a normal way.

This worked fine in 0.6.4.

bug

Most helpful comment

The problem is gone.

All 18 comments

https://github.com/HelloZeroNet/ZeroNet/blob/174e8d3c19e4dbe53bdab95db0aa3de416249df3/zeronet.py#L14-L18

There should be something wrong here

This worked fine in 0.6.4.

In 0.6.4, zeronet would shutdown suddenly and damage the databases, because you have to kill the process
I don't know how it behaves on unix systems

I used 0.6.4 without problems, I didn't observe it to spontaneously shut down.

It works based on my test.
Does it prints "Error setting up SIGTERM watcher" error on startup?
Can you please try if it works if you replace the zeronet.py with this file:
https://raw.githubusercontent.com/HelloZeroNet/ZeroNet/dd46a64e7911439ae4239d21e55c5fdb5cd6188f/zeronet.py

No, it didn't print this message.
I will try with your file tomorrow.

On Gentoo I replace new «zeronet.py» to /usr/share/zeronet/ and recompile (pyc, pyo)

/etc/init.d/zeronet start
 * Starting ZeroNet ...   

in debug.log (with log level ERROR) before stopping:

ValueError: unknown address family 10
[2019-02-23 13:38:41,412] ERROR    - Unhandled exception
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
  File "/usr/share/zeronet/src/Site/SiteAnnouncer.py", line 383, in announcePex
    num_added = peer.pex(need_num=need_num)
  File "/usr/share/zeronet/src/Peer/Peer.py", line 275, in pex
    address = helper.unpackAddress(peer)
  File "/usr/share/zeronet/src/util/helper.py", line 104, in unpackAddress
    return socket.inet_ntop(socket.AF_INET6, packed[0:16]), struct.unpack_from("H", packed, 16)[0]

Zites is works, and I try stop daemon:

/etc/init.d/zeronet stop
 * Stopping ZeroNet ...
....................
 * start-stop-daemon: 1 process refused to stop 

Process «zeronet» is present. No other errors in debug.log

The error seems unrelated to the issue. What version of python you have?

yes, not related to the problem

net-vpn/zeronet-9999-r1::raiagent USE="tor -debug -meek" PYTHON_TARGETS="python2_7"

root ~ # eselect python list
Available Python interpreters, in order of preference:
  [1]   python2.7
  [2]   python3.6

process list: /usr/bin/python2.7 -O /usr/share/zeronet/zeronet.py --config_file /etc/zeronet.conf main

diff -u zeronet.py zeronet_old.py 
--- zeronet.py  2019-02-23 13:21:04.016566700 +0200
+++ zeronet_old.py  2019-02-23 13:19:10.777557989 +0200
@@ -12,9 +12,11 @@
     main = None
     try:
         import signal
+        try:
+            signal.signal(signal.SIGTERM, lambda signum, stack_frame: sys.exit(0))
+        except Exception as err:
+            print("Error setting up SIGTERM watcher: %s" % err)

-        signal.signal(signal.SIGTERM, lambda signum, stack_frame: sys.exit(0))
-        
         app_dir = os.path.dirname(os.path.abspath(__file__))
         os.chdir(app_dir)  # Change working dir to zeronet.py dir
         sys.path.insert(0, os.path.join(app_dir, "src/lib"))  # External liblary directory

please check the python version with python2.7 -V

root ~ # python2.7 -V
Python 2.7.15

dev-lang/python
     Available versions:  
     (2.7)  2.7.15
...

This bug makes 0.6.5 unusable. -(

Same for me on Arch Linux ARM. The sys.exit(0) from the signal handler does not terminate the process. Are there multiple processes or threads?

I have tested that sys.exit won't stop non-daemon threads.

I didn't update the FreeBSD port because all services are supposed to be stopped and started with the standard commands, and zeronet doesn't stop.

./zeronet.py sometimes prints a KeyboardInterrupt trace and exists, sometimes just prints Shutting down... and does nothing - for Ctrl+C.

No reaction for sending SIGTERM. (neither in regular or debug log)

python* -V:
| python | 3.6.5 |
| python2 | 2.7.15 |
| python3 | 3.6.5 |
| python3.5 | 3.5.5 |
| python3.5m | 3.5.5 |

zeronet.py from dd46a64e7911439ae4239d21e55c5fdb5cd6188f does not solve the SIGTERM issue (for me).

Sending SIGTERM _does_ something.

I sent sigterm on 2019-03-19 20:44:24. Here is the long (29M) debug log: https://files.fm/u/wjpfqdks

TL;DR it looks like ZeroNet closes connections in reaction to a SIGTERM

This should be fixed in rev3857 by shutting down the same way as ctrl+c does: https://github.com/HelloZeroNet/ZeroNet/commit/74ce0c50ff315ac3ed5e63981f8b41877c479cb4

The problem is gone.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergei-bondarenko picture sergei-bondarenko  Â·  3Comments

sermont picture sermont  Â·  3Comments

DaniellMesquita picture DaniellMesquita  Â·  3Comments

yurivict picture yurivict  Â·  4Comments

ghost picture ghost  Â·  4Comments