diff --git a/.github/workflows/test-only.yml b/.github/workflows/test-only.yml index 1c89f2fa858..8a288740bfb 100644 --- a/.github/workflows/test-only.yml +++ b/.github/workflows/test-only.yml @@ -201,6 +201,30 @@ jobs: # @todo - scan the container log to see the right "graceful shutdown" text exists docker rm sig-test + - name: Test changedetection.io wsgi fail case + run: | + + echo "wsgi fail case: Address already in use" + docker run --name sig-test test-changedetectionio bash -c ' + # just occupy external port 5000 + python -m http.server 5000 --bind 0.0.0.0 & + # just a second. + sleep 1 + # port conflicts and shutdown. + PORT=5000 python changedetection.py -d /datastore' || true & + sleep 5 + docker ps -a + docker logs sig-test 2>&1 | grep 'Address already in use' || exit 1 + docker logs sig-test 2>&1 | grep 'Shutting down datastore thread' || exit 1 + test -z "`docker ps|grep sig-test`" + if [ $? -ne 0 ] + then + echo "Looks like container was running when it shouldnt be" + docker ps + exit 1 + fi + docker rm sig-test + - name: Dump container log if: always() run: | diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index e2bf5ddc954..4f7e5adecfc 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -182,13 +182,19 @@ def hide_referrer(response): s_type = socket.AF_INET6 if ipv6_enabled else socket.AF_INET - if ssl_mode: - # @todo finalise SSL config, but this should get you in the right direction if you need it. - eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen((host, port), s_type), - certfile='cert.pem', - keyfile='privkey.pem', - server_side=True), app) + try: + if ssl_mode: + # @todo finalise SSL config, but this should get you in the right direction if you need it. + eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen((host, port), s_type), + certfile='cert.pem', + keyfile='privkey.pem', + server_side=True), app) - else: - eventlet.wsgi.server(eventlet.listen((host, int(port)), s_type), app) + else: + eventlet.wsgi.server(eventlet.listen((host, int(port)), s_type), app) + except Exception as e: + app.config.exit.set() + datastore.stop_thread = True + logger.critical(e) + sys.exit(2)