onionshare icon indicating copy to clipboard operation
onionshare copied to clipboard

Figure out new way to shutdown flask service

Open micahflee opened this issue 2 years ago • 1 comments

When we stop an OnionShare service, this web.force_shutdown() function is run:

    def force_shutdown(self):
        """
        Stop the flask web server, from the context of the flask app.
        """
        # Shutdown the flask service
        try:
            func = request.environ.get("werkzeug.server.shutdown")
            if func is None and self.mode != "chat":
                raise RuntimeError("Not running with the Werkzeug Server")
            func()
        except Exception:
            pass

        self.running = False

        # If chat, shutdown the socket server
        if self.mode == "chat":
            self.socketio.stop()

I noticed when running tests we get this warning:

  /home/circleci/repo/cli/onionshare_cli/web/web.py:342: UserWarning: The 'environ['werkzeug.server.shutdown']' function is deprecated and will be removed in Werkzeug 2.1.

I looked into this, and they give their rationale for deprecating this here: https://github.com/pallets/werkzeug/issues/1752

Also, we should probably run Flask in production instead of dev.

micahflee avatar Mar 06 '22 21:03 micahflee

~~Waitress might be interesting?~~ Nevermind, it works in principle, but it doesn't support gzip, so we are better off moving to Nginx I guess...

mig5 avatar Mar 07 '22 06:03 mig5