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

__init__/fix: the app will shutdown if wsgi fail. #2193

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 7
docker ps -a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep is a little longer. the reason will be appeared in docker ps -a

This comment was marked as outdated.

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: |
Expand Down
28 changes: 19 additions & 9 deletions changedetectionio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,23 @@ 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)

else:
eventlet.wsgi.server(eventlet.listen((host, int(port)), s_type), 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)

except Exception as e:
Constantin1489 marked this conversation as resolved.
Show resolved Hide resolved
import threading
import time
app.config.exit.set()
datastore.stop_thread = True
while len(threading.enumerate()) > 1:
time.sleep(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#app.config.exit.set()
#datastore.stop_thread = True
while len(threading.enumerate()) > 1:
    print(threading.enumerate())

shows the reason.

logger.critical(e)
sys.exit(2)
Loading